Mongoose - Sharing models/schema between databases

163 views
Skip to first unread message

uma namasivayam

unread,
Mar 29, 2015, 10:41:44 PM3/29/15
to mongoo...@googlegroups.com
Hi

I love mongoose for what it does.

I am wondering whether mongoose has the capability to share models and schema among database connection.

Here is the scenaro below

SchemaA and modelA are initialized to connA assigned to DBa (same localhost but different dbname)
SchemaB and modelB are initialized to connB assigned to DBb(same localhost but different dbname)

In this setup everything works perfect. I am able to query both in the same routine etc. But when i try to link document in DBb modelB (with SchemaA)

_ModelAid: {type: ObjectId, ref:SchemA}. I am able to run queries but when i run populate i get the missing Schema error.

Am i missing something here? or is there no such functionality?

What i am trying to accomplish is i want to segregate data in databases but still want to have a link between the two.

Thanks
Sam

Anthony Ettinger

unread,
Mar 29, 2015, 11:58:52 PM3/29/15
to mongoo...@googlegroups.com
you can make a schema plugin.

--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

uma namasivayam

unread,
Mar 30, 2015, 1:22:59 AM3/30/15
to mongoo...@googlegroups.com
Is there a Tuturial or documentation please

Anthony Ettinger

unread,
Mar 30, 2015, 3:17:14 AM3/30/15
to mongoo...@googlegroups.com
probably documented somewhere, but here's a plugin I use for voting.



On Sun, Mar 29, 2015 at 10:22 PM, uma namasivayam <umama...@gmail.com> wrote:
Is there a Tuturial or documentation please
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

uma namasivayam

unread,
Mar 30, 2015, 9:53:38 AM3/30/15
to mongoo...@googlegroups.com
Hi Anthony,

I went through that plugin and i am not sure whether i will be able to share schemas or link populate schemas spanning different dbs.

Sam

etti...@gmail.com

unread,
Mar 30, 2015, 12:09:22 PM3/30/15
to mongoo...@googlegroups.com
You would create a module probably. 

-- Anthony

Uma Namasivayam

unread,
Mar 30, 2015, 12:23:36 PM3/30/15
to mongoo...@googlegroups.com
Has this been done before ? 

I doubt whether it is even possible to do so

Uma
You received this message because you are subscribed to a topic in the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongoose-orm/dtKjdragves/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongoose-orm...@googlegroups.com.

Valeri Karpov

unread,
Mar 30, 2015, 4:46:50 PM3/30/15
to mongoo...@googlegroups.com
Use the model name instead of the schema instance in your ref field: http://mongoosejs.com/docs/populate.html . Otherwise, should work so long as you have the correct model name
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to a topic in the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongoose-orm/dtKjdragves/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongoose-orm+unsubscribe@googlegroups.com.

Uma Namasivayam

unread,
Mar 30, 2015, 7:25:20 PM3/30/15
to mongoo...@googlegroups.com
Valeri

I should have been clear. I did use the model name in the ref field ref:'ModelA' but I still get the same error missing schema when I use populate. 

Uma
To unsubscribe from this group and all its topics, send an email to mongoose-orm...@googlegroups.com.

Uma Namasivayam

unread,
Mar 31, 2015, 1:33:06 AM3/31/15
to mongoo...@googlegroups.com
I finally solved it after updating it to 4.0.1.

Great work!

Uma

On Mar 30, 2015, at 3:46 PM, Valeri Karpov <valeri...@10gen.com> wrote:

To unsubscribe from this group and all its topics, send an email to mongoose-orm...@googlegroups.com.

Valeri Karpov

unread,
Apr 7, 2015, 12:26:21 PM4/7/15
to mongoo...@googlegroups.com
Glad to hear 4.0.1 helped :)
To unsubscribe from this group and all its topics, send an email to mongoose-orm+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages