MongoDB is a document-oriented NoSQL database, and its syntax is different from that of relational databases such as MySQL or PostgreSQL. Here are some examples of MongoDB syntax:
To create a collection in MongoDB, use the db.createCollection() method:
db.createCollection("myCollection")
To insert documents into a collection, use the insertOne() or insertMany() method:
db.myCollection.insertOne({name: "John", age: 30})
db.myCollection.insertMany([{name: "Jane", age: 25}, {name: "Bob", age: 35}])
To query documents from a collection, use the find() method:
db.myCollection.find({name: "John"})
This will return all documents in the myCollection collection where the name field is “John”.
To update a document in a collection, use the updateOne() or updateMany() method:
db.myCollection.updateOne({name: "John"}, {$set: {age: 40}})
This will update the first document in the myCollection collection where the name field is “John”, setting the age field to 40.
To delete documents from a collection, use the deleteOne() or deleteMany() method:
db.myCollection.deleteOne({name: "John"})
This will delete the first document in the myCollection collection where the name field is “John”.