MongoDB集合连字符名称

编程入门 行业动态 更新时间:2024-10-11 19:24:05
本文介绍了MongoDB集合连字符名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Node.js程序将数据插入MongoDB数据库.我已将数据插入名为"repl-failOver"的集合中.

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("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".

When I use the Mongo shell and list down the collections in the database using show collections I am able to see the collection "repl-failOver".

如何从mongo shell中为该集合运行find命令?

How do I run a find command from the mongo shell for this collection?

推荐答案

使用以下语法:

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

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

您可以在执行查询中找到更多信息手册部分:

如果mongo shell不接受集合名称,则 名称包含空格,连字符或以."开头的实例 数字,您可以使用其他语法来引用该集合,例如 在以下内容中:

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()

更多推荐

MongoDB集合连字符名称

本文发布于:2023-11-29 13:46:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646555.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符   名称   MongoDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!