Using BSON or converting it to JSON to use it in AngularJS

1,936 views
Skip to first unread message

Bhanu Chaudhary

unread,
May 29, 2013, 6:22:17 AM5/29/13
to reacti...@googlegroups.com
 Hi ,
I am using angularjs as my frontend and scala based tiny HTTP service DSL while using reactivemongo as my driver to my mongodb . I am very new to nosql and mongodb ,
I just want to know is it possible to use BSON directly in angularjs or any other easy way to covert bson to json .
Thank you in advance

Pascal Voitot Dev

unread,
May 29, 2013, 7:35:54 AM5/29/13
to reacti...@googlegroups.com
You need to search for Bson<->Json library in Javascript but I don't know if it exists.

What you can do also is to use directly Json from/to Mongo with ReactiveMongo and the BSON/JSON conversion is managed by ReactiveMongo (using Play/Json)

Pascal
 

--
You received this message because you are subscribed to the Google Groups "ReactiveMongo - http://reactivemongo.org" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reactivemong...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Bhanu Chaudhary

unread,
May 29, 2013, 8:12:47 AM5/29/13
to reacti...@googlegroups.com
 Hi,
Thanks for the prompt reply anyways can I use the BSON/JSON conversion is managed by ReactiveMongo without using play
Thanks in advance

Pascal Voitot Dev

unread,
May 29, 2013, 8:18:37 AM5/29/13
to reacti...@googlegroups.com
yes you can but it's not yet out-of-the-box and require a few manual actions (not quite complicated)...

You can use Play/Json outside play because it's an independent library. Have a look at my article there:
http://mandubian.com/2013/02/21/play-json-stand-alone/

You should also be able to depend on Play Plugin (it's a simple JAR) and simply import the packages provided in json.scala & jsoncollection.scala which provide everything you need to use Json directly with ReactiveMongo.
https://github.com/zenexity/Play-ReactiveMongo/tree/master/src/main/scala/play/modules/reactivemongo

Don't care about controllers...

Pascal

Bhanu Chaudhary

unread,
May 29, 2013, 12:20:29 PM5/29/13
to reacti...@googlegroups.com
Thank you very much . Saved me a lot of effort and time which could have gone in vain :-)

Jun Yamog

unread,
May 29, 2013, 6:01:51 PM5/29/13
to reacti...@googlegroups.com
Hi,

I am not sure why would you forgo with play.  It is really straight forward using angular + play + reactive mongo.  Only thing we needed to do is to transform the id <-> _id / $oid.  Then just some validators on create and update of mongo docs.



On Thu, May 30, 2013 at 4:20 AM, Bhanu Chaudhary <bhan...@gmail.com> wrote:
Thank you very much . Saved me a lot of effort and time which could have gone in vain :-)

Pascal Voitot Dev

unread,
May 29, 2013, 6:10:11 PM5/29/13
to reacti...@googlegroups.com
On Thu, May 30, 2013 at 12:01 AM, Jun Yamog <jky...@gmail.com> wrote:
Hi,

I am not sure why would you forgo with play.  It is really straight forward using angular + play + reactive mongo.  Only thing we needed to do is to transform the id <-> _id / $oid.  Then just some validators on create and update of mongo docs.


that's the kind of stuff we need to add to play-reactivemongo but it's so trivial that we haven't done it yet :D

Jun Yamog

unread,
May 29, 2013, 6:59:52 PM5/29/13
to reacti...@googlegroups.com
Yes its really trivial, I think for me I would be happy enough if its on the sample app.

// json transformers so mongo specific stuff is not given to the front end

val mongoToFE = (

  (__.json.update((__ \ 'id).json.copyFrom((__ \ '_id \ '$oid).json.pick))) andThen

  (__ \ '_id).json.prune andThen

  stripCreatedAndModified

)

Reply all
Reply to author
Forward
0 new messages