在我的 mongodb 数据库中使用游标,需要有关修复查询的指导
Using cursor in my mongodb database, need guidance on fixing my queries
所以现在我想使用游标来查找所有适合团体、价格范围小于或等于 3 并且有超过 50 条评论至少有 5 条评论的餐厅 "useful"票数;
db.business.find({$and:[{"attributes": /.*GoodForGroups: True.*/i},{review_count:{$gte:50}},{"attributes.RestaurantsPriceRange2":{$lte:3}}]})
但是到目前为止这个查询没有任何结果,它有什么问题吗?
这也是目前为止我能想到的我的游标,如果你发现有什么不对的地方,请随时更改。
var myCursor=db.business.find({$and:[{"attributes": /.GoodForGroups: True./i},{review_count:{$gte:50}},{"attributes.RestaurantsPriceRange2":{$lte:3}}]},{business_id:true, _id: false})
while(myCursor.hasNext()){
db.reviews.find({$and:[{business_id:myCursor.next().business_id},{"useful":{$gte: 5}}]});
}
首先,您不需要在查询中使用 $and,mongodb 默认执行 $and。
其次,您正在尝试查询文档的键,这是不可能的。
第三,您的 GoodForGroups 应该有一个布尔值。您在这里不需要正则表达式。
请运行:
db.business.find({"attributes.GoodForGroups": true},{review_count:{$gte:50}},{"attributes.RestaurantsPriceRange2":{$lte:3}})
所以现在我想使用游标来查找所有适合团体、价格范围小于或等于 3 并且有超过 50 条评论至少有 5 条评论的餐厅 "useful"票数;
db.business.find({$and:[{"attributes": /.*GoodForGroups: True.*/i},{review_count:{$gte:50}},{"attributes.RestaurantsPriceRange2":{$lte:3}}]})
但是到目前为止这个查询没有任何结果,它有什么问题吗?
这也是目前为止我能想到的我的游标,如果你发现有什么不对的地方,请随时更改。
var myCursor=db.business.find({$and:[{"attributes": /.GoodForGroups: True./i},{review_count:{$gte:50}},{"attributes.RestaurantsPriceRange2":{$lte:3}}]},{business_id:true, _id: false})
while(myCursor.hasNext()){
db.reviews.find({$and:[{business_id:myCursor.next().business_id},{"useful":{$gte: 5}}]});
}
首先,您不需要在查询中使用 $and,mongodb 默认执行 $and。
其次,您正在尝试查询文档的键,这是不可能的。
第三,您的 GoodForGroups 应该有一个布尔值。您在这里不需要正则表达式。
请运行:
db.business.find({"attributes.GoodForGroups": true},{review_count:{$gte:50}},{"attributes.RestaurantsPriceRange2":{$lte:3}})