Tag: schema

如何在Mongoose.js模式中表示ES6映射

我正在使用ES6 Map作为“specs”属性,我已经在下面的TypeScript接口中表示了这一点: import { IModel } from './model'; export interface IProduct extends IModel { name: string; description: string; specs: {[key: string]: string }; img: string[]; } 不过,这似乎并不适用于mongoose模式。 之后,失败了,我试图在我的模式下面的代码,这似乎不工作: const ProductSchema = new Schema({ name: String, description: String, specs: [{key: String, value: String}], img: String[] }); 如果有人能帮我找出正确的方法来做到这一点,我将非常感激。

无法使用mongoosejs进行填充

为什么我不能得到结果,而试图填充我的计划(我使用mongoosejs)。 在我的情况下,我的类别,子类别,sububcategoryscheme不使用_id。 我使用自定义ID。 这是我的产品scheme: ….. categoryId: { type: String, ref: 'Catgory', required: true }, subcategoryId: { type: String, ref: 'Subcategory', required: true }, subsubcategoryId: { type: String, ref: 'Subsubcategory', required: true }); const Product = mongoose.model('Product', product); module.exports = Product; 这是我的产品控制器: 'getOne': function(req, res, next) { if (typeof req.params.id !== 'string') return res.send({ 'error-code': 3 […]

mongoose:“投入embedded失败的价值在path。 不能使用'in'运算符search'_id'

我尝试在一个对象数组中保存一个数组时遇到了一些麻烦。 我收到服务器的以下响应: { [CastError: Cast to embedded failed for value "\'maxbeds: 4\'" at path "saved_searches"] message: 'Cast to embedded failed for value "\\\'maxbeds: 4\\\'" at path "saved_searches"', name: 'CastError', kind: 'embedded', value: '\'maxbeds: 4\'', path: 'saved_searches', reason: [TypeError: Cannot use 'in' operator to search for '_id' in maxbeds: 4] } 这是我的模式: var mongoose = require('mongoose'), […]

Node.JS中的架构重要吗?

我正在为一个我刚刚构build的表单创build一个巨大的模式…据说我的模式顺序必须模仿forms顺序,还是只能按照我把它们放入的顺序input所有的input? 下面的例子。 可以这样吗? // link to mongoose var mongoose = require('mongoose'); // define the article schema var mapSchema = new mongoose.Schema({ created: { type: Date, default: Date.now }, dd1: { type: String, default: '' }, dd2: { type: String, default: '' }, com1: { type: String, default: '' }, com2: { type: String, default: '' […]

TypeError:Dbschema(Mongoose Schema)不是函数

我正在尝试使用mongoose使用MEAN_Stack创build一个简单的registry单。 这是我的models / dbSchema.js var mongoose = require('mongoose'); var Schema = mongoose.Schema; var User = new mongoose.Schema({ FirstName: String, LastName: String, City : String, Email : String, Userid : String, Password: String }); module.export = mongoose.model('user', User); 这是我的server.js var express = require('express'); var app = express(); var bodyParser = require('body-parser'); var jwt = require('jsonwebtoken'); app.use(express.static(__dirname […]

mongoose – 使用单个集合的多个模式

我试图计划我的api,例如: /animals // returns all animals /animals/dogs // returns all dogs /animals/cats // returns all cats /animals/dogs/:id // returns dog 所以,我有“猫”和“狗”的单独模型,因为它们将包含独特的属性,但都使用“动物”模式作为基础插件。 所以我的问题是关于在哪里存储数据,我的select是: 1)单一收集 – 在一个集合中存储猫和狗,这将使得通过单个查询获得“/动物”的数据相对容易 2)多个集合 – 将猫和狗存储在单独的集合中,这将使得数据存储更加合理,但是当获取“/动物”的数据将需要多个查询和数据串联时。 还有其他的select,我错过了,或者一个首选的方法? 谢谢

JSDoc + Mongoose:如何loggingMongoose模型?

我有Mongoose 模式和一个模型 : var MyClientSchema = new mongoose.Schema({ fist_name: { type: String }, phone_number: { type: String } }); var MyClient = mongoose.model('MyClient', MyClientSchema); 我应该怎样使用JSDoc MyClient和/或MyClientSchema来从WebStorm获取从WebStorminheritance的两个方法(如remove, findOne, find和从模式inheritance的phone_number and first_name ?

理解mongoose

是否正确定义了下面的模式,或者writing是否需要writing: [Schema.Types.Mixed] 或者 writing: [{}] ? 也就是说,如果您有一组词典 – [{},{},{}] – 除非您创build另一个模式并embedded它,否则不能预定义内部结构。 这是对文档的正确解释吗? http://mongoosejs.com/docs/schematypes.html var blogSchema = new mongoose.Schema({ title: String, writing: [{ post: String, two: Number, three : Number, four : String, five : [{ a: String, b : String, c : String, d: String, e: { type: Date, default: Date.now }, }] }], }); […]

mongoose + express + mongodb声明多个模式后不能从数据库获取数据

我是新来的node.js和我有问题时访问多个mongoose模式声明。 模型中的//schema.js var mongoose = require('mongoose'); var Schema = mongoose.Schema , ObjectId = Schema.ObjectId; //User Schema var userSchema = new Schema({ id: ObjectId, firstname: {type: String, require: true}, lastname: {type: String, require: true}, username: {type: String, unique: true, require: true}, password: {type: String, require: true}, role: {type: [String], require: true} }) var User = mongoose.model('User', […]

用StrongLoop自动创buildMySQL表

我想用MySql的Strongloop,但不知道如何迁移或自动创build表到MySql数据库。 是否至less有一种方法将模型导出到MySql模式或我必须手动创build表? 我一直在尝试与MySQL演示应用程序,并通过了一段时间的文档,但没有运气 – http://docs.strongloop.com/display/DOC/MySQL+connector 谢谢!