Can we use the “.” symbol in MongoDB collection name?

MongoDBDatabaseBig Data Analytics

Yes, we can use the “.” symbol in MongoDB collection name. Let us create a collection with documents −

> db.getCollection('demo28.example');
web.demo28.example
>
>
> db.getCollection('demo28.example').insertOne({"Name":"Chris","Age":32});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5e15fbe48f2315c2efc48e6b")
}
> db.getCollection('demo28.example').insertOne({"Name":"Bob","Age":31});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5e15fbec8f2315c2efc48e6c")
}
> db.getCollection('demo28.example').insertOne({"Name":"David","Age":33});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5e15fbf38f2315c2efc48e6d")
}

Display all documents from a collection with the help of find() method −

> db.getCollection('demo28.example').find().pretty();

This will produce the following output −

{
   "_id" : ObjectId("5e15fbe48f2315c2efc48e6b"),
   "Name" : "Chris",
   "Age" : 32
}
{ "_id" : ObjectId("5e15fbec8f2315c2efc48e6c"), "Name" : "Bob", "Age" : 31 }
{
   "_id" : ObjectId("5e15fbf38f2315c2efc48e6d"),
   "Name" : "David",
   "Age" : 33
}
raja
Published on 02-Apr-2020 15:58:42
Advertisements