Which characters are NOT allowed in MongoDB field names?


Do not use $ symbol or period (.) because these characters are not allowed for MongoDB field names. The field shouldn’t start with $.

Here is an example of the allowed characters −

> db.charactersAllowedDemo.insertOne({"Employee Name" : "John"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5c7fefbc8d10a061296a3c6d")
}

Display all documents from a collection with the help of find() method. The query is as follows −

> db.charactersAllowedDemo.find().pretty();

The following is the output −

{
   "_id" : ObjectId("5c7fefbc8d10a061296a3c6d"),
   "Employee Name" : "John"
}

Updated on: 29-Jun-2020

563 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements