MongoDB 通过连字符的集合的名称

我使用该计划 Node.js 将数据插入数据库中 MongoDB. 我将数据插入收集名称 "repl-failOver".


var mongoClient = require/"mongodb"/.MongoClient;
mongoClient.connect/"mongodb://localhost:30002/test", function/err, db/ {
if /err/ throw err;
db.collection/"repl-failOver"/.insert/ { "documentNumber" : document++}, function /err, doc/ {
if /err/ throw err;
console.log/doc/;
}/;
db.close//;
}/;


当我使用时 Mongo shell 并列出数据库中的集合
show collections

, 我可以看到集合 "repl-failOver".

如何运行命令 find 的 mongo shell 这个系列?
已邀请:

帅驴

赞同来自:

使用此语法:


db['repl-failOver'].find/{}/


或者


db.getCollection/'repl-failOver'/.find/{}/


您可以在该节中找到更多详细信息
http://docs.mongodb.org/manual ... eries
手册:

如果一个 mongo shell 不接受集合的名称,
例如,如果名称包含空格,则为连字符或从
数字,您可以使用替代语法进行集合的链接
显示下面:


db["3test"].find//

db.getCollection/"3test"/.find//

帅驴

赞同来自:

访问具有定义字符的集合时,您会收到此错误 /
-

,
_

,

/. 我解释说明

旁路路径,但大多数是你所需要的只是做

db.getCollection/"repl-failOver"/.insert/.../

要回复问题请先登录注册