查看我的 imageDetails 集合的文档:
> db.imageDetails.find()
{ "_id" : ObjectId("5a187f4f2d4b2817b8448e61"), "keyword" : "sachin", "name" : "sachin_1511554882309_1.jpg", "fullpath" : "Download/sachin_1511554882309_1.jpg" }
{ "_id" : ObjectId("5a187f4f2d4b2817b8448e62"), "keyword" : "sachin", "name" : "sachin_1511554882317_2.jpg", "fullpath" : "Download/sachin_1511554882317_2.jpg" }
{ "_id" : ObjectId("5a187f4f2d4b2817b8448e63"), "keyword" : "sachin", "name" : "sachin_1511554882319_3.jpg", "fullpath" : "Download/sachin_1511554882319_3.jpg" }
{ "_id" : ObjectId("5a187f4f2d4b2817b8448e64"), "keyword" : "sachin", "name" : "sachin_1511554882319_4.jpg", "fullpath" : "Download/sachin_1511554882319_4.jpg" }
{ "_id" : ObjectId("5a187f4f2d4b2817b8448e65"), "keyword" : "sachin", "name" : "sachin_1511554882320_5.jpg", "fullpath" : "Download/sachin_1511554882320_5.jpg" }
{ "_id" : ObjectId("5a187f4f2d4b2817b8448e66"), "keyword" : "sachin", "name" : "sachin_1511554882320_6.jpg", "fullpath" : "Download/sachin_1511554882320_6.jpg" }
{ "_id" : ObjectId("5a187f4f2d4b2817b8448e67"), "keyword" : "sachin", "name" : "sachin_1511554882320_7.jpg", "fullpath" : "Download/sachin_1511554882320_7.jpg" }
{ "_id" : ObjectId("5a187f4f2d4b2817b8448e68"), "keyword" : "sachin", "name" : "sachin_1511554882320_8.jpg", "fullpath" : "Download/sachin_1511554882320_8.jpg" }
{ "_id" : ObjectId("5a187f4f2d4b2817b8448e69"), "keyword" : "sachin", "name" : "sachin_1511554882320_9.jpg", "fullpath" : "Download/sachin_1511554882320_9.jpg" }
{ "_id" : ObjectId("5a187f4f2d4b2817b8448e6a"), "keyword" : "sachin", "name" : "sachin_1511554882320_10.jpg", "fullpath" : "Download/sachin_1511554882320_10.jpg" }
{ "_id" : ObjectId("5a187f4f2d4b2817b8448e6b"), "keyword" : "sachin", "name" : "sachin_1511554882321_11.jpg", "fullpath" : "Download/sachin_1511554882321_11.jpg" }
{ "_id" : ObjectId("5a187f4f2d4b2817b8448e6c"), "keyword" : "sachin", "name" : "sachin_1511554882321_12.jpg", "fullpath" : "Download/sachin_1511554882321_12.jpg" }
{ "_id" : ObjectId("5a187f4f2d4b2817b8448e6d"), "keyword" : "sachin", "name" : "sachin_1511554882321_13.jpg", "fullpath" : "Download/sachin_1511554882321_13.jpg" }
{ "_id" : ObjectId("5a187f4f2d4b2817b8448e6e"), "keyword" : "sachin", "name" : "sachin_1511554882321_14.jpg", "fullpath" : "Download/sachin_1511554882321_14.jpg" }
{ "_id" : ObjectId("5a187f4f2d4b2817b8448e6f"), "keyword" : "sachin", "name" : "sachin_1511554882322_15.jpg", "fullpath" : "Download/sachin_1511554882322_15.jpg" }
>
我希望nodejs中字段&#39; <&#39; 的不同值作为mongodb中的替换值,如:
> db.imageDetails.distinct('keyword');
[ "sachin" ]
我试过但在节点js mongodb模块中没有找到任何有效的方法,所以如果有聚合选项或更有效的东西,请建议任何方法。我被卡住了:
MongoClient.connect(url, function(err, db) {
if (err)
throw err;
var cursor = db.collection(collectionName).find(findQuery);
cursor.each(function(err, doc)