Tag: mongo

将不同types的值从Node.js插入到MongoDB集合中

我用Node.js和MongoDB使用sails web框架来创build我自己的网站。 现在,我在创build一个新用户时遇到了一些困难,并且在发送一个post请求的时候向我的'users'集合中插入了值(从不同的types:Number,Array,Object)。 我无法弄清楚,为什么这里唯一的types是'string',当我改变types为'数字'例如,并通过邮递员发送一个post请求,这是popup的错误: "message": "Resolver error: \"age\" has wrong type", "name": "PARAMETER_WRONG_TYPE", 这是用户控制器: create: function(req, res){ var expectedInputs = [ { name: 'idsid', type: 'string', required: true } , { name: 'age', type: 'Number', required: true } , { name: 'last_name', type: 'string', required: true } ]; SanitizeService.allReqParams(req.allParams(), expectedInputs) .then(function(sanitizedInputs){ var user = {}; […]

js和mongodb不同

Model.distinct("Age").done(function(err, ward) { if(err) return next(err); if(!ward) return next(); res.json(ward); }); 执行这个代码后,它会出现以下错误: TypeError: Object [object Object] has no method 'distinct' 但robomongo独特的作品。 我怎样才能纠正错误?

部署App Sails js Heroku | 应用程序错误

我运行我的应用程序时出现错误。 应用程序错误。 应用程序发生错误,您的页面无法送达。 请稍后重试。 如果您是应用程序所有者,请查看日志以获取详细信息。 Heroku日志: May 05 08:17:00 game app/web.1: > node app.js May 05 08:17:04 game app/web.1: error: Error: Failed to connect to MongoDB. Are you sure your configured Mongo instance is running? May 05 08:17:04 game app/web.1: Error details: May 05 08:17:04 game app/web.1: { [MongoError: connect ECONNREFUSED] name: 'MongoError', message: 'connect […]

在风帆蒙戈使用填充方法的深度关联?

我是sails.js的新手,我正在使用“Mongodb的sails.js” 。 我在使用填充在我的风帆应用程序的深度关联有问题。 我有这样的关系: Category has many to many relationship with Article. City has one to many relationship with Areas. Article has one to one relationship with City and Areas. Category.js module.exports = { schema: true, attributes: { //add referecnce to other article Articles: { collection: 'Article', via:'ref_category_id' }, category_name: { type:'string', required: true, unique: […]

在sails中实现推送通知

我是新来的风帆js。 我想在sails中为android和IOS实现推送通知。 我用mongodb使用Sails js。 任何人都可以帮助我的configuration或哪个插件来实现推送通知在JS风帆。 提前致谢。

Sails.js模型:创build2个关联自失败

我很新的Nodejs和帆。 我正在实现一个类似于Twitter的服务器。 在用户模型中,应该有两个字段:follower和follow,这两个字段是模型“用户”本身的关联。 我的问题是,当模型只有1个关联,追随者或追随者,它的工作。 但是,当追随者和追随者都包括在内时,就会出现错误。 代码是这样的: module.exports = { attributes: { alias: { type:'string', required: true, primaryKey: true }, pwd: { type: 'string', required: true }, follower: { collection: 'user', via: 'alias' }, following:{ collection: 'user', via: 'alias' } } 该代码将导致这样的错误: usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/references.js:115 throw new Error('Trying to associate a collection attribute to a model tha ^ […]

错误:使用mongo数据库提升sails应用程序时,钩子('orm')加载失败

我得到这个错误:当尝试使用mongoDB提升一个sails应用程序时,钩子('orm')加载失败。 这是我的connections.js文件: module.exports.connections = { mongodb: { adapter : 'sails-mongo', host : 'localhost', port : 27017, database : 'mydb1' } }; 这是我的models.js文件: module.exports.models = { connection: 'mongodb' }; 这是我的local.js文件: module.exports = { connections: { mongodb: { host : 'localhost', port : 27017, database : 'mydb1' } } } Sails v 0.10.1 任何想法为什么会发生这种情况? 谢谢

处理Sails.js中的数据库环境configuration

我所遇到的问题与以下官方文档的引用有关: 注意如果模型使用适配器的任何连接,那么所有连接到该适配器的连接都将被加载到sails.lift上,无论模型是否实际使用它们。 在上面的示例中,如果将模型configuration为使用localMysql连接,则localMysql和remoteMysql都将在运行时尝试连接。 因此,根据环境将连接configuration拆分并将其保存到适当的环境特定configuration文件中,或者注释掉不想激活的任何连接。 如何configuration生产服务器的连接? 我的connections.js文件如下所示: module.exports.connections = { mongoDev: { adapter: 'sails-mongo', host: 'localhost', port: 27017, user: 'username', password: 'password', database: 'database' }, mongoLive: { adapter: 'sails-mongo', host: 'host.mongolab.com', port: 31681, user: 'user', password: 'password', database: 'database' } }; 并在我的环境configuration文件,我有: development.js module.exports = { models: { connection: 'mongoDev' } }; production.js module.exports = { […]