1
我試圖將對象數組保存到貓鼬模式,但它無法將數據加載到laptop
模式我只看到一個包含id
的插入。 如何將json對象的數組保存爲mongoose模式?如何將json對象的數組保存爲貓鼬?
controller.js
var laptopData = [
{ name: 'Hp probook 15.1',cpu:'2.4GHZ' ,ram: '4GB', harddrive: '160GB',Brand:'HP'},
{ name: 'Hp probook 15.1',cpu:'2.4GHZ' ,ram: '4GB', harddrive: '160GB',Brand:'Hp'},
{ name: 'Hp probook 15.1',cpu:'2.4GHZ' ,ram: '4GB', harddrive: '160GB',Brand:'Hp'},
{ name: 'Hp probook 15.1',cpu:'2.4GHZ' ,ram: '4GB', harddrive: '160GB',Brand:'Hp'},
{ name: 'Hp probook 15.1',cpu:'2.4GHZ' ,ram: '4GB', harddrive: '160GB',Brand:'Hp'},
{ name: 'Hp probook 15.1',cpu:'2.4GHZ' ,ram: '4GB', harddrive: '160GB',Brand:'Hp'},
{ name: 'Hp probook 15.1',cpu:'2.4GHZ' ,ram: '4GB', harddrive: '160GB',Brand:'HP'},
{ name: 'Hp probook 15.1',cpu:'2.4GHZ' ,ram: '4GB', harddrive: '160GB',Brand:'Hp'},
{ name: 'Hp probook 15.1',cpu:'2.4GHZ' ,ram: '4GB', harddrive: '160GB',Brand:'Hp'},
{ name: 'Hp probook 15.1',cpu:'2.4GHZ' ,ram: '4GB', harddrive: '160GB',Brand:'Hp'},
{ name: 'Hp probook 15.1',cpu:'2.4GHZ' ,ram: '4GB', harddrive: '160GB',Brand:'Hp'}
]
var laptop = new Laptop({laptopData});
laptop.save(function(err) {
// we've saved the dog into the db here
if (err) throw err;
});
schema.js
'use strict';
var mongoose = require('bluebird').promisifyAll(require('mongoose'));
var LaptopSchema = new mongoose.Schema({
name: String,
ram:String,
harddrive:String,
Brand: String
});
module.exports = mongoose.model('Laptop', LaptopSchema);
檢查[存儲JSON對象在貓鼬字符串鍵]行(http://stackoverflow.com/questions/17497875/storing-json-object-in-mongoose-string-key) – yaitloutou
請在這裏發佈用戶mongoose模式以幫助調試 – georoot
@georoot模式添加到問題 – hussain