var Commentschema = { Data:{type:objectid, ref: ' Data '},//data data table, where data ID from:{type:objectid is stored, ref: ' User '},/ /USER User table, save user ID replay:[ {from : {type:objectid, ref: ' User '}, to
InquireBefore our collection has been created successfully, let's start with the first step--query.There are many types of queries, such as conditional query, filter query, and so on, today we only learn the most basic find query.Example :1.find
automatically dereferenced each time, then the 1 queries that are possible in the nested method may need to be n+1 times (N is the length of the comments array in the message).Examples are as follows:Defined in User.js:var userschema = new Schema ({ name: { type:string, unique:true }, password: { type:string,Defined in Msgboard.js:var messageschema = new Schema ({ user_id: { type:mongoose. Schema.objectid, ref: ' User ' }, content:string, time : { type:date, default:
1. When using mongoose, install mongoose first. Open the command line and execute $ npminstallmongoose2. Connect to the mongodb database and add the following two lines of code to app. js. [Javascript] varmongooserequire ( amp; #39; mongoose amp; #39;); mongoose. con...
1. When using
Node. JS Database Chapter--mongoose ODM Introduction MongooseAlmost all languages have a native database connection driver, this we have learned on the last time, such as Java Jdbc,mysql-connector, but the actual development in order to pursue efficiency will not use the original connection, not always establish a connection, the last one, Our registration and landing each write a connection operation, at least we should encapsulate a database connect
, stored procedures, views, and so on in the Visual Studio environment. You can also view the data in the database and create your own query by hand or by using the graphical interface of Query Builder (Builder). Also, when we create a strongly typed dataset for the DAL, we need to point Visual Studio to the target database as the dataset data source. Although we can provide the Yun 敳 Mongoose 搨 in due course??? Oё The database connection information
1. When using mongoose, install mongoose first, open the command line, and execute $ npm install mongoose
2. Connect to the mongodb database and add the following two lines of code in app. js.
[Javascript]Var mongoose = require ('mongoose ');
Developers ' ability to handle complex data structures is a measure of the developer's level ... Recently found that some of the nested data structures, hierarchical data structure processing capacity is not enough ... These are the things that often make you dizzy ... Serious impact on development efficiency ... Just a little bit low summed up the next ...First, MongoDB design hierarchical relational data (here is mainly about mongoose)① assumes that
DB; = "db" $id://point to collection.document._id; = "OID" } MongoDB does not a support joins. Introduction to the next Mongoose population: Connect two documents and find the properties of a subdocument through the parent document: var parentschema=new Schema ({
name:string,
children:{type:schema.types.objectid, ref: ' Children '}
})
var childschema=new schema ({
name:string
})
//define children in parent schema, point to
to port 28018.
After MongoDB is started, we can use mongo (Interactive shell) to manage the database. Run mongo directly in the bin directory. You can see that:
Mongo Shell connects to the test database by default. It also tells us that you can enter help to view help. You can type help and press enter to see which commands are available.
Note: by default, mongod does not contain authentication when it is started. After the client is connected, you can perform any operations, such as creating
This example is based on the previous logindemo (see using cookies to stay logged in ) and we introduced MongoDB to save user data. To run this example, if the MongoDB data is going to work (see node. JS Development Primer--mongodb and Mongoose). The result of the run of the example is the same as the previous Logindemo. So, let's just analyze the changes in the project itself when the database is introduced.Installing MongooseUnder command-line envir
default is jade, and the template is already configured in the project.
Iv. Introduction to the Express Builder project
1, the MyApp project's organization is as follows:
2, Package.json This can be said to be a module management package, project information and the version number of the module, in fact, you will find in the Project module initialization is the configuration to find the generated.
3, App.js is the project's start-up document, can be said to be the core of the project. Mai
when adding skip () and limit (), a parameter of true is required. Otherwise, the total number of results that match the query criteria is returned Fuzzy query: Db.collection.find ({"Name":/ab/}) The above is a common query, if the work encountered more complex requirements, you can check the document to solve. 3.7 Using Visual Tools4 Mongoose 4.1 Mongoose IntroductionMongoose Library in short, a conve
Prepare: Install Node.js,mongodb,mongoose,webstorm
Here I use the mongoose to deal with. Mongoose is an object model tool for MongoDB that can work in asynchronous environments. Specific learning content See official website http://mongoosejs.com/docs/index.html
1, start to use Mongoose, must first install, open comman
In the previous section, we talked about the Library management system login, I believe that we have a jade template and angular JS also have a understanding, today we look at a book information input. Here we are going to use the NoSQL database, which is used by MongoDB in this blog post. Ok. Mongo DB Installation I don't have to say much, then the node. JS Platform uses mongodb what extension package we use, I think it is mongoose more appropriate,
Basic connectionFirst, create Express project TestmonExpress TestmonSecond, streamline App.jsvar express = Require ("Express"); var app = Express (); App.get (function(req, res) { res.send (' Add one piece of data at a time ') ; }); var server = App.listen (,function() { console.log ("Please visit in Browser: http://localhost : (");});Three: Enter the engineering directory to install Mongoose and introduce dependencies:NPM Install--save Mongoos
bin directory, you can see the following figure:
The MONGO shell is connected to the test database by default, and also tells us that you can enter help to view it. You can type help and return to see what commands are available.
Note that the Mongod default startup without authentication, the client connected to the operation can be casually, build a library, add a check, such as all can be. If you want to restrict user rights, you can configure yourself, I will go straight down here.
Ins
This can be said to be the module management package, project information and module version number, in fact, you will find in the Project module initialization is the configuration here to find the generated.3, App.js is the project's starting document, can be said to be the core of the project. Mainly write some public functions.4, the bin file has a no suffix of the www file, which is the entry file of the project, configure the Web service port and some monitoring events.5, Node_modules is
Label:ObjectiveFrom the installation of the environment in the native (win8.1) environment to finish this demo about less than two weeks, just started in the local installation environment and did not knock a demo, from the beginning of the weekend and intermittent to write a, according to the inertia of thinking to write a deletion and change to check it, One is to experience the magic of node. JS, and the second is to look at the API of node. JS, Express, and
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.