senecajs / seneca-mongo-store

Node.js Seneca data storage plugin for MongoDB
MIT License
35 stars 42 forks source link

Not able to run basic example #35

Closed rkdrepo closed 8 years ago

rkdrepo commented 8 years ago

I was exploring seneca-mongo-store with the example provided and I realize that its storing data into memory. How do I force it to write into mongo.

Code I am using:

var seneca = require('seneca')()
seneca.use('entity')

seneca.use('mongo-store', {
  uri: 'mongodb://127.0.0.1:27017/testdb'
})

seneca.ready(function () {
  var dev = seneca.make$('device')
  dev.id  = 2
  dev.name = 'pii'
  dev.save$(function (err,dev) {
    console.log( "dev.id = "+dev.id  )
  })
})

Also I tried to add {default_plugins: {'mem-store':false}} but it generates error.

2016-05-06T09:44:17.451Z iet7mymndo4p/1462527856926/8385/- WARN act     -               -       -       seneca: No matching action pattern found for { cmd: 'save',  role: 'entity',  ent: $-/-/device;id=2;{name:pii},  name: 'device',  base: undefined,  zone: undefined }, and no default result provided (using a default$ property).  act_not_found   {args:{ cmd: 'save',  role: 'entity',  ent: $-/-/device;id=2;{name:pii},  name: 'device',  base: undefined,  zo       Error: seneca: No matching action pattern found for { cmd: 'save',  role: 'entity',  ent: $-/-/device;id=2;{name:pii},  name: 'device',  base: undefined,  zone: undefined }, and no default result provided (using a default$ property).
    at Object.errormaker [as error] (/home/cts328367/webservice/node_modules/seneca/node_modules/eraro/eraro.js:94:15)
    at Object.execute_action [as fn] (/home/cts328367/webservice/node_modules/seneca/seneca.js:1088:25)
    at Immediate._onImmediate (/home/cts328367/webservice/node_modules/seneca/node_modules/gate-executor/gate-executor.js:136:14)
    at tryOnImmediate (timers.js:543:15)
    at processImmediate [as _immediateCallback] (timers.js:523:5)
mcdonnelldean commented 8 years ago

@rahulkrdas If you remove the mongo plugin, does the code work (it should default to in mem store)

rkdrepo commented 8 years ago

Yes, without mongodb plug in its going to members store.

luhtonen commented 8 years ago

I found that Quick Example provided in plugin README is not working with newest version of seneca 2.1.0 because part of functionality was moved to seneca-entity module. I've managed to run example with the following changes: Install Need to install seneca-entity as dependency npm install seneca-entity Quick Example Need to add following line seneca.use('entity'); after defining seneca. Here's full code:

const seneca = require('seneca')();
seneca.use('entity');
seneca.use('mongo-store', {
  name: 'test',
  host: '127.0.0.1',
  port: 27017
});

seneca.ready(() => {
  var apple = seneca.make$('fruit')
  apple.name  = 'Pink Lady'
  apple.price = 0.99
  apple.save$((err,apple) => {
    console.log( "apple.id = "+apple.id  )
  });
});

I can see new entries in Mongo database:

> db['fruit'].find()
{ "_id" : ObjectId("57a44808451caf7013e1326d"), "name" : "Pink Lady", "price" : 0.99 }
mihaidma commented 8 years ago

Best place to look for samples is the tests. Just merged an updated sample. Sample on how to use entity: https://github.com/senecajs/seneca-mongo-store/blob/master/test/mongo.test.js#L28

Sample on how to disable mem-store: https://github.com/senecajs/seneca-mongo-store/blob/master/test/mongo.test.js#L23

I'll close this. Please open a separate issue if something is not working. Thank you.

soundaryathiagarajan commented 8 years ago

works for me as well ..

db['fruit'].find() { "_id" : ObjectId("57aa30f4b117631587a9bfe2"), "name" : "Pink Lady", "price" : 0.99 }

rkdrepo commented 8 years ago

Its working. Thanks for your help @mihaidma .

vishwasvadavi commented 8 years ago

Yes... putting the seneca.use('entity') after declaring seneca variable works for me. Thanks @luhtonen. This was very helpful.

mike-casey-rehearsal commented 8 years ago

thanks @luhtonen ! chaining .use('entity) immediately after seneca fixed this for me too (when running mongo-store)

iamNoah1 commented 7 years ago

For me this only worked after also adding seneca.use('basic')

alvarezgarcia commented 7 years ago

Always mongo-store at last plugin..