【问题标题】:mongodb querying collection starting with _mongodb查询以_开头的集合
【发布时间】:2013-07-28 01:56:28
【问题描述】:

基本上问题很简单:

如何对以 _ 开头的集合发出查询?

例如,如果我有 2 个集合 test_test,我在 mongoshell 中尝试 db.test.findOne()db._test.findOne(),第一个按预期工作,而第二个告诉我 TypeError: db._testhas no properties (shell):1

【问题讨论】:

    标签: mongodb mongo-shell


    【解决方案1】:

    将其放在引号中并使用 getCollection 方法。看到这个article

    示例要创建集合 _foo 并插入 { a : 1 } 文档,请使用以下操作:

    db.getCollection("_foo").insert( { a : 1 } )
    

    要执行查询,请使用 find() 方法,如下所示:

    db.getCollection("_foo").find()
    

    【讨论】:

      猜你喜欢
      • 2021-01-30
      • 2017-09-15
      • 1970-01-01
      • 2014-02-09
      • 1970-01-01
      • 2019-05-09
      • 2016-09-27
      • 2015-11-13
      • 1970-01-01
      相关资源
      最近更新 更多