2016-08-03 49 views
1

我试图做一个'找到所有'的资源在一个mongodb集合。mongo find()产生没有输出与eval

我可以得到数确定:

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()" 

它产生

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

我也试过find({})

该重新似乎不是身份验证错误。第一个查询工作并产生一个计数。我还可以

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

进入蒙戈外壳和

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

而且看到正确的JSON输出。

+0

关怀给集合名称?这真的是table123? – 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())"