简体   繁体   English

mongoDb查询以使用$ in和$ or来搜索值?

[英]mongoDb query to search values using $in and $or?

var norm = [ 'may', 'funny', 'top funny', 'dinner', 'dog', 'hello', 'flo', 'sake', 'hai', 'video', 'rhymes', 'fine', 'good', 'public', 'testing', 'irish', 'hii', 'babies', 'coffee', 'happy', 'working', 'comedy', 'india', 'best', 'top', 'feelings', 'krishna', 'test' ] var norm = [['may','funny','top funny','dinner','dog','hello','flo','sake','hai','video','rhymes','好”,“好”,“公开”,“测试”,“爱尔兰”,“ hii”,“婴儿”,“咖啡”,“快乐”,“工作”,“喜剧”,“印度”,“最佳” ,“ top”,“ feelings”,“ krishna”,“ test”]

schema.find( { $or: [ {"head":{"$in":norm}}, {"key":{"$in":norm}} ],"privacy":{"$ne":"Private"} },function(err,res){});

i have to list the result in ascending order as per the norm but i didnt get the exact result from the above query. 我必须按照规范升序列出结果,但我没有从上述查询中获得确切的结果。

That query wont ever work, this is the format for find schema. 该查询将永远无法工作,这是查找架构的格式。 db.collection.find(query, projection) where projection are the fields you wish to return from the query if it is a success. db.collection.find(query, projection)其中,投影是您希望从查询中返回的字段(如果成功的话)。 Also in your query is both norm is a array right? 同样在您的查询中,两个norm都是数组吗?

Your is wrong: schema.find( { $or: [ {"head":{"$in":norm}}, {"key":{"$in":norm}} ],"privacy":{"$ne":"Private"} },function(err,res){}); 您的输入是错误的: schema.find( { $or: [ {"head":{"$in":norm}}, {"key":{"$in":norm}} ],"privacy":{"$ne":"Private"} },function(err,res){}); .

This "privacy":{"$ne":"Private"} is not included in the query that is why, it is in the projection section. "privacy":{"$ne":"Private"}未包含在查询中,这就是原因,它在投影部分中。

should be something like this : schema.find( { $or: [ {"head":{"$in":norm}}, {"key":{"$in":norm}}],"privacy":{"$ne":"Private"}}); 应该是这样的: schema.find( { $or: [ {"head":{"$in":norm}}, {"key":{"$in":norm}}],"privacy":{"$ne":"Private"}}); .

Here is a elegant way for this query. 这是查询的一种优雅方式。

Schema.find( { $or: [ {"head":{"$in":norm}}, {"key":{"$in":norm}}]).where("privacy").ne("Private").exec(function(err,doc){});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM