如何将SQL查询转换为mongodb查询

时间:2020-11-06 14:36:29

标签: mongodb

我在项目中使用MongoDB Atlas。我试图建立查询,但是遇到了一些问题。

enter image description here

select top 20 * 
from users 
where _id not in (select following=0
                     from users 
                     where _id = myuserid)

我尝试转换查询,但不能。

"{\"collection\":\"users\",\"stages\":[{\"$match\":{\"$and\":[{\"status\":\"active\"},{\"_id\":{\"$ne\":{\"$oid\":[{\"$match\":[{\"_id\":{\"$oid\":\"%%args.user\"}},{\"following\":{\"$size\":0}}]},{\"$project\":{\"_id\":1}}]}}}]}}]}"

您能帮我解决问题吗?。

谢谢。

1 个答案:

答案 0 :(得分:0)

可以通过以下方式完成:

db.collection.find({
  userid: {
    $ne: myuserid
  }
}).limit(20)

相关问题