How can you enforce that all documents in the 'books' collection have a 'title' field in MongoDB? - Study24x7
Social learning Network
5 followers study24x7 13 Dec 2024 09:59 AM study24x7 study24x7

How can you enforce that all documents in the 'books' collection have a 'title' field in MongoDB?

A

db.books.update({}, {$set: {title: {$exists: true}}})

B

db.books.createIndex({title: 1}, {unique: true})

C

db.books.setValidator({title: {$exists: true}})

D

db.books.modifySchema({title: {$exists: true}})

study24x7
Write a comment
Related Questions
500+   more Questions to answer
Most Related Articles