There is no join feature in MongoDB, so joins and associated queries cannot be used with joins, the populate method is encapsulated in mongoose, and the field (property) can be specified as a reference to another schema when defining a schema. When querying a document, you can use the Populate method to find the specified field value for another document or docum
. objectId, ref: 'clazz '}) StudentSchema. statics = {findClazzNameByStudentId: function (studentId, callback) {return this. findOne ({_ id: studentid00000000.populate('clazzid'0000.exe c (callback)} // other methods are omitted ..} module. exports = StudentSchema
As you can see, the master needs to set the ClazzID to ref to Clazz, and the dependency is the name of the Model you created. to query Clzz, use populat
Data model and Base operation templateIn order to make the engineering structure clear, the establishment of data Model (SCHEMA) and the base operation template of adding and deleting and modifying are named as collection in database design (corresponding to the table definition in relational database) and stored in the Models folder.Creation of schema and model:Schema is the data schema in mongoose, which can be understood as the table structure defi
_id and ref.Note: ObjectId, number, String, and buffer can also be used as ref.Save refSaving the ref for other document works the same as saving the property, just assigning the _id value.var aaron =NewPerson ({_id:0, Name: ' Aaron ', age:100}); Aaron.save (function(err) {if(ERR)returnHandleError (ERR); varStory1 =NewStory ({title:"Once upon a Timex.", _creator:aaron._id//Assign the _id from the person }); Story1.save (function(err) {if(ERR)returnHandleError (ERR); //thats it! });});Populati
Mongoose learning comprehension (recommended) and mongoose learning Comprehension
1. Create schemas
How to Create schemas:
var userSchema = new mongoose.Schema({ name: String, email: String, createdOn: Date });
Schemas has the following data types:
String
Number
Date
Boolean
Buffer
ObjectId
Mixed
Array
In particular, the ObjectId, Mixed, and Array types must be described. The follow
Mongoose getting started with mongooseNo matter what database you use as the db service, connect is an essential step. Method 1:
@ Param {String} uri @ param {Object} options @ param {Function} callbackconnect (uri, [options], [callbakc]) returns the mongoose Object. connect ('mongodb: // localhost/test', {mongos: true}, function (err, result) {if (err) {console. log ('error ing to MongoDB Database. '+ err)
= {findclazznamebystudentid: function (studentid, callback) {return this. findone ({_ ID: studentid00000000.populate('clazzid'0000.exe C (callback)} // other methods are omitted ..} module. exports = studentschema
As you can see, the master needs to set the clazzid to ref to clazz, and the dependency is the name of the model you created. to query clzz, use populate
Below is the model
var
(conditions, [fields], [options], [callback])PopulatepopulateUsed to view the associated document contents, that is, the ref related fields of the document associated with the query set fieldModel.populate (Docs, Options, [CB (ERR,DOC)])Exampleyield article.findone ({_id:id}, {title: 1, Author: 1}). Populate (1, _id: 1}}) //find _id as ID for the category field of the article corresponding to the classification name in the category table and Id// Mult
MongoDB does not join, but sometimes we need to refer to other collection documents, this time we need to populate.We can populate a single document, multiple document, plain object, multiple plain objects, or all object returned by query.var mongoose = require (' Mongoose '); var Schema = Mongoose. Schema;var Personsc
monkey), single-threaded, so inefficient, not suitable for real-time query # #二: Through a good design data model to do
VarPostschema= New Schema({Author: {Type: String},Title: {Type: String, Require : True},Content: {Type: String, Require : True},Comment: {Owner: {Type: String},Subject: {Type: String, Require},Content: {TypeString, require} } }); mypostmodel. ({ ' comment.subject ' : /car*/ }). (function (err,) { do some stuff Span class= "KWD" >with the Result ... }); ym16
The convenience of Mongoose operation set is indeed not general, but it is mainly because you design the set in reference, however, it is a little troublesome for Mongoose to limit and identify the combination of sets when using ref to associate a set. But it doesn't matter. It's easy to use.
1. usage of the ref associated document in mongoose
2. query related
()Introduction to using the Mongoose module to manipulate MongoDB modulesMongoose is a module that corresponds to a Nodejs object and a document in MongoDB.The mongoose supports both strong mode and modeless mode.Install Mongoose:$ NPM Install MongooseLet's look at the final directory structure:Configuration and LinksThe format of the link: (You can also omit th
background:The Dicom column introduces the installation and use of the deconstructed PACs (distributed PACs) Orthanc, as well as the analysis of the main modules such as plug-ins and SQLite databases, and introduces the Web Server,mongoose embedded in Orthanc. Relying on Mongoose, this lightweight web Server,orthanc is a good implementation of the RESTful API and traditional DICOM service integration, which
Background:Orthanc is a new DICOM server introduced in this column, with a lightweight, rest-enabled feature that turns any computer running Windows and Linux systems into a dicom server, or Minipacs. Orthanc embedded in a variety of modules, database management is simple, and does not rely on third-party software. So through the analysis of Orthanc source code can learn to build a dicom system in various aspects, such as SQLite embedded database, googlelog Log library, DCMTK Medical Dicom Libra
background:Orthanc is a new DICOM server introduced in this column, with a lightweight, rest-enabled feature that turns any computer running Windows and Linux systems into a dicom server, or Minipacs. Orthanc embedded in a variety of modules, database management is simple, and does not rely on third-party software. So through the analysis of Orthanc source code can learn to build a dicom system in various aspects, such as SQLite embedded database, googlelog Log library, DCMTK Medical Dicom Libra
Many people ask: how do I share mongoose in Nodejs to establish a database connection, and then use this database connection elsewhere in this application?Many foreign postings have been discussed, but the relative dullness of the country, the popularity of technology and the degree of enthusiasm for technology are also evident.Anyway .... Back to TopicThe following example shows you how to make a database connection and use it elsewhere in the progra
Today we will learn mongoose, what is mongoose, it is in MongoDB what is the relationship, it can be used to do?MongoDB is an open source NoSQL database, compared to MySQL-like relational database, it is more light and flexible, it is very suitable for use in the case of large data size, not strong transaction. At the same time, it is also an object database, no tables, rows and other concepts, there is no
Detailed description of node. js's addition, deletion, modification, and query operations based on the mongoose module, nodejsmongoose
MongoDB
MongoDB is a Javascript-based database with a JSON storage format, while Node is also a JavaScript-based environment (library ), therefore, the combination of node and mongoDB can reduce the time space overhead caused by data conversion.
Mongoose
It is an object mode
1 /********** User table by Jaysir 2015.6.212 ***********3 *********** can search the following keywords to view the features that are not implemented4 *********** 5 *********** TODO: Not completed6 *********** Done: Completed7 *********** totest: Pending Test8 *********** notest: no test required9 *********** Waiting: function to be determinedTen *********** One *********** Interface: (not implemented to add groups, change the group of Friends and other functions) A *********** findonebyemai
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.