【问题标题】:How to get critarea result with specific key and value from collection of mongo database?如何从 mongodb 数据库集合中获取具有特定键和值的标准结果?
【发布时间】:2016-11-14 17:09:54
【问题描述】:

假设,我们有一个名为 posts

的集合
    {
    "_id": ObjectId("5146bb52d8524270060001f3"),
    "post_text":"This is a sample post" ,
    "user_name": "mark",
    "post_privacy": "public",
    "post_likes_count": 0
    },
   {
    "_id": ObjectId("5146bb52d8524270060001f4"),
    "post_text": "This is a sample post",
    "user_name": "pramod",
    "post_privacy": "public",
    "post_likes_count": 0
   }

假设我们在 mysql 中有相同的表。 我想将同样的 sql 结果查询到 mongo 中。

查询是:select post_likes_count from posts where user_name="mark"; 我们如何在 mongodb 中得到相同的结果?

【问题讨论】:

标签: node.js mongodb express mongoose


【解决方案1】:

回答:

db.posts.find({user_name:"mark"});

mongo playground

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-10
    • 2021-07-05
    • 2019-01-13
    • 1970-01-01
    • 2014-03-07
    • 2020-07-18
    • 2022-10-26
    • 2020-12-08
    相关资源
    最近更新 更多