Tag: mongo

单程方向,风帆和mongodb

我有个问题。 我觉得我做错了什么。 我有两个模型:tutorType和学生。 这是我的学生 module.exports = { attributes: { tutor1Name:'string', tutor1Type: { model: 'tutorType' }, contact: { type: 'numeric' }, } }; 这是我的TutorType module.exports = { attributes: { libelle: "string" } }; 我使用预定义的蓝图来插入。 当我插入一个新学生时,我有返回的响应: { "name": "Luke", "tutor1Type": "Biological", "createdAt": "2015-07-13T17:57:12.526Z", "updatedAt": "2015-07-13T17:57:12.526Z", "id": "55a3fbf8c9e93bf0266a63a8" } 应该tutor1Type是一个对象,而不是一个string? 其实,我可以把我想要的string。 我希望能够把我在TutorType与我的学生的外键只有行。 我做什么错了? 编辑 只需在我的数据库中添加一下。 当我发送tutorType的ID到我的控制器。 它在db中添加一个“Object(hashID)”。 我认为这是一个好消息。 […]

帆js mongodb填充

我想使用.populate()Sails js和MongoDB,所以我做了这样的事情: 我正在使用最新版本的Sails和MongoDB和Node。 我的模型看起来像: // User.js module.exports = { attributes: { name: { type: 'string' }, pets: { collection: 'pet', via: 'owner' } } }; // Pet.js module.exports = { attributes: { name: { type: 'string' }, owner: { model: 'user' } } }; 我使用了以下与文档相同的内容: User.find() .populate('pets') .exec(function(err, users) { if(err) return res.serverError(err); res.json(users); }); […]

如何在mongodb的风帆中find指定的字段?

在MySQL中,我可以通过使用以下命令检索指定的列: User.find({select:['email']})….. 现在我正在移动到mongodb,我试过了: User.find({select:['email']})….. User.find({},{email:1})….. User.find({},{fields: {email:1}})…. 但是他们都没有工作。 我怎么能在MongoDB中做到这一点? 顺便说一句:我可以通过使用官方的mongodb驱动程序来做到这一点,它非常简单,并且与API文档完全匹配,所以我正在重新思考应该使用官方驱动程序( 我不想浪费时间来查询和解决问题这 ),但我不想失去吃水线的能力和灵活性。 任何build议或意见是赞赏。 db.collection('user').find({},{email:1})

如何在sails中configurationnode-pushserver?

我正在用mongodb使用js风格。我需要为android和ios实现推送通知。 我怎么能实现它。 我在网上search了很多关于风帆js的推送通知的东西,但我没有find任何有用的资源在js中实现推送通知。 我尝试了节点推送服务器,但没有得到如何在sails中configurationnode-pushserver,所以任何人都可以帮助我这个。

如何查询朋友post在特定路线的Rest API中

我正在SailsJS工作,我正在尝试为我的移动应用程序构build一个REST API后端,以允许Newsfeedpath,所以如果我在前端查询JSON,我可以从www.website.com/用户/ ID /新闻源。 控制器获取每个用户的朋友和他们的post,并按照时间顺序显示在该路线上的JSON。 我来自一个客观的C背景,所以忍受我的新手。 config/routes.js module.exports.routes = { '/': { view: 'homepage' }, 'get /user/:id/newsfeed': { controller: 'UserController', action: 'newsfeed' } }; Model/User.js var User = module.exports = { //User attributes attributes: { facebookId: 'string', accessToken: 'string', location: 'string', email: 'string', first_name: 'string', last_name: 'string', about: { interests: 'string', goals: 'strings', headline: 'string', […]

等待asynchronous任务完成nodejs

我正在创build一个应用程序,用户可以有很多房间,每个房间可以有很多频道,这是我的代码时,检索房间和相应的渠道: getRooms: function (req, res) { User.find({id: req.cookies.claver_id}).exec(function (err, result) { if (err) { return res.send(400); } rooms = result[0].rooms; if (rooms.length === 1) {//No room defaults to [''] return res.send(400); } var roomsObj = {}; var roomsArr = [];//we will place the roomsObj inside the roomsArr var chansObj = {}; var chansArr = []; […]

将3毫米的数据迁移到MongoDB

我正在尝试将MySQL数据移动到MongoDB。 logging超过300万行。 每次修改我的节点启动脚本后,内存都会耗尽 "scripts": { "debug": "node debug app.js", "start": "node –max_old_space_size=5120 –optimize_for_size –max_executable_size=5120 –stack_size=5120 app.js", "test": "node ./node_modules/mocha/bin/mocha test/bootstrap.test.js " } 我尝试使用正常的callback函数,并承诺,什么都没有。 整体function var citiesInit = function(_setup) { var connection = mysql.createConnection({ host : 'localhost', user : 'root', password : 'password', database : 'WorldCities' }); connection.connect(); connection.query('SELECT * FROM thecities', function(err, rows, fields){ if […]

如何在不保存nodejs |的情况下validationlogging sailsjs | 吃水线

我寻求这种性质的东西 //validation rules in model "User" attributes: { age: { required: true, type: 'numeric' } }, //now in controller, i want to be able to do this Recipe.validate({age: 'An invalid age because it is a string. I except a validation error as response'}); 问题是,它不工作..它抱怨前validation不可用,等等

希望在库存和类别模型(mongodb)中执行sails js中的连接查询

我想获取同类别的类别和库存,我可以通过使用填充来获取库存和它的类别..但是我想要反转它..但我不知道如何..我使用填充函数,但它不工作 库存模型“使用严格”; /** * Inventory * @description :: Model for storing Inventory records */ module.exports = { schema: true, autoPk:false, attributes: { // Fill your attributes here id: { type: 'string', primaryKey: true }, name: { type: 'string' }, brand: { type: 'string' }, price: { type: 'float' }, discount: { type: 'string' }, description: […]

如何使用Sails-mongoselectid文件?

User.find({ _id: { '!': user.id } }, function foundFriends (err, friends) { if(err) return next(err); res.view({ friends: friends }); }); MONGODB : { _id: ObjectId("53b942f7c8638f7b17670acc"), name: "PH", admin: true, online: false, encryptedPassword: "$2a$10$PjcPRgL67ZSOWDjmEwTkvu30xKeDXdCwgZ.D0.bjyDRw9sOfS/4UK", createdAt: ISODate("2014-07-06T12:37:11.522Z"), updatedAt: ISODate("2014-07-09T18:22:47.25Z") } 此代码不起作用,我想通过Idselect文档。 我不知道该怎么做才能解决这个问题。 感谢您的帮助。