MongoDB collection hyphenated name

前端 未结 2 1227
时光取名叫无心
时光取名叫无心 2021-02-01 12:46

I\'m using Node.js program to insert data into a MongoDB database. I have inserted data into a collection named \"repl-failOver\".

var mongoClient = require(\"mo         


        
2条回答
  •  名媛妹妹
    2021-02-01 13:16

    Use this syntax:

    db['repl-failOver'].find({})
    

    or

    db.getCollection('repl-failOver').find({})
    

    You can find more information in the Executing Queries section of the manual:

    If the mongo shell does not accept the name of the collection, for instance if the name contains a space, hyphen, or starts with a number, you can use an alternate syntax to refer to the collection, as in the following:

    db["3test"].find()
    
    db.getCollection("3test").find()
    

提交回复
热议问题