Mongodb
Last updated
Was this helpful?
Last updated
Was this helpful?
VSCode: cosmoDB https://code.visualstudio.com/docs/azure/mongodb
MongoDBCompass (cannot insert command)
Robot3T
install environment
install driver
npm install --save mongodb
Use option upsert is convenient for achieving insertOrUpdate mechanism.
avoid calling findOne multiple time, use Cursor.each instead.
http://mongodb.github.io/node-mongodb-native/2.2/quick-start/quick-start/
How to specify Shared Key
Range
Increase opportunity to find thhe single Shard that holds the required dataset.
Hashed
Needs to scatter the queries to all shards and find the dataset
One-to-One
One-to-Many
Studio-Game Example
With/ Without Embedded Documents
Many-to-Many
User-Role Example
One User can have multiple roles such as READ only role and WRITE role.
One Role can have Multiple Users such as John , Mary.
Plugins
http://mongoosejs.com/docs/plugins.html
you can add property in a common usage
Schema
Model is useful when scale out the applications
Populate
Get the reference content by populate the field of reference Id
Or can use dynamic reference type to reference content in runtime,
the Calendar Model contains field of reference
```
CalendarEvent.find(deviceEventQuery).populate("reference");
eventType: { type: String, required: true, enum: EVENT_TYPES }, title: { type: String, required: true }, reference: { type: ObjectId, //reference to Device / PlayList EventSchema required: true, refPath: "eventType" }, ```
Operators $in, $gte, $lte, $gt, $lt, $contains $nin
https://docs.mongodb.com/manual/reference/database-profiler/
keyExamined
less than nreturned
https://docs.mongodb.com/v3.4/reference/database-profiler/
VersionError