2016-08-03 10 views
1

私はmongodbコレクション内のリソースをすべて検索しようとしています。mongo find()はevalで出力を生成しません

私はカウントOKを取得することができます。

mongo ip:port/database1 -u correctusername -p correctpassword 
--authenticationDatabase admin --eval "db.getCollection('collection_123').count()" 

しかし、私はそれを微調整しようとすると、

mongo ip:port/database1 -u correctusername -p correctpassword 
--authenticationDatabase admin --eval "db.getCollection('collection_123').find()" 

をそれは私もfind({})

を試してみました

MongoDB shell version: 2.4.0 
connecting to: ip:port/database1 
DBQuery: database1.collection_123 -> { } 

を生成ザ認証エラーではないようです。最初のクエリが機能し、カウントが生成されます。私はまた、

mongo ip:port/database1 -u correctusername -p correctpassword 
--authenticationDatabase admin 

モンゴシェルと

db.getCollection('collection_123').find() 

に取得し、正しいJSON出力を見ることができます。

+0

ケアのですか?これは本当にテーブル123ですか? – Oct

+0

@Octコレクションに更新しました。単なるテストコレクションです。 – Michael

答えて

1

私が見つけた唯一の方法は、

mongo ip:port/database1 -u correctusername -p correctpassword 
--authenticationDatabase admin --eval "db.collection.find().forEach(printjson)" 

にあるが、さらなるコマンドは、ソートまたは制限するように、動作しませんように、出力は、シェルと同じではありません。

更新

より良い解決策は、コレクションの名前を付けること

mongo ip:port/database1 -u correctusername -p correctpassword 
--authenticationDatabase admin --eval "printjson(db.collection.find().toArray())" 
関連する問題