javascript 蒙戈数据库

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 蒙戈数据库相关的知识,希望对你有一定的参考价值。

var mongoose = require("mongoose");

mongoose.connect("mongodb://localhost/cat_app2");

//create the cat scheme
var catScheme = new mongoose.Schema({
    name: String,
    age: Number,
    temperament: String
});


var Cat = mongoose.model("Cat", catScheme);

//thats how you create a new item (cat here)
var george = new Cat({
    name: "George",
    age: 11,
    temperament: "Grouchy"
});

george.save(function (err, cat) { //callback run when save finished
    if (err) {
        console.log("SOMTHiNG WENT WRONG");
    }
    else {
        console.log("WE JUST SAVE A CAT TO THE DB");
        console.log(cat);
    }
});

以上是关于javascript 蒙戈数据库的主要内容,如果未能解决你的问题,请参考以下文章