Posts

Showing posts with the label mongoose

node-fibers : yielding data out of a Fiber

node-fibers : yielding data out of a Fiber I just started working with node-fibers to actually try out something I had in mind to make it easier to make mongoose queries a little more easy to deal with. Unfortunately , I don't seem to understand what I'm doing wrong to get the users returned using the yield() to the main function that called Fiber. users yield() var Fiber = require("fibers"); var mongoose = require("mongoose"); var User = require('./user'); mongoose.connect('mongodb://localhost/fibers'); function wrapper() { let f = Fiber(function(){ var results; var fiber = Fiber.current; User.find({},function(err,users){ var results = Fiber(function(){ fiber.run(users); }).run(); }) results = Fiber.yield(); Fiber.yield(results); }); return f.run.bind(f); } var result = wrapper()(); console.log(result); use sync in...

GraphQL Schema for mongoose Mixed type (Schema.Types.Mixed)

GraphQL Schema for mongoose Mixed type (Schema.Types.Mixed) I have a Mongoose schema with the following structure: import mongoose from 'mongoose'; const PropertySchema = new mongoose.Schema({ name: { type: String }, description: { type: String }, value: { type: mongoose.Schema.Types.Mixed }, unit: { type: String }, }); export default mongoose.model('Property', PropertySchema); I need to build a GraphQL query for the given data. How do I handle the Mixed type for the value property ? value Here is my try: import NodeInterface from '../interfaces'; import PropertyModel from '../../models/Property'; const fields = { id: { type: new GraphQLNonNull(GraphQLID), resolve: (obj) => dbIdToNodeId(obj._id, "Property") }, name: { type: GraphQLString }, description: { type: GraphQLString }, value: { type: <<< What ...

Proper Mongoose Subdocument Relation

Proper Mongoose Subdocument Relation I have a model const userSchema = Schema({ username: String }) const invitationSchema = Schema({ decision: String, user: { type: Schema.ObjectId, ref: 'User' } }) const groupSchema = Schema({ name: String, invitations: [{ type: Schema.ObjectId, ref: 'Invitation' }] }) So the basic model looks like group { name invitations [ user { username } ] } As user i would like to get all groups that i have invitations for const user = getContextUser() Group.find({ 'invitations.user': user._id }) But it doesn't seem to work, i could use a property group referring to Group schema in Invitation model, but i want the good way approach Group Invitation How to i get all groups that user have invitations for Don't look at this below, this is my actual model representation in json, just in case // GROUP { "_id": ObjectId("5b3901dd9a8c0e6790af4ee8"), "i...