Search code examples
angularjsionic-frameworkloopbackjsstrongloopmobile-development

Strongloop not able use mongodb function


I'm using AngularJS Sdk from Strongloop to develop the mobile application with ionicframework.

In between the development progress, i failed to use the mongodb function from angular. I always get the unexpected result without any error message. Hope can get some help. Thanks.

var feed$ = Feed.find({
            filter : {
                    $or : [{ accountId : "569a9fc898e6f58b0329eefc" }, { accountId : "569a9fa098e6f58b0329eefb" }]
            }
        });

Solution

  • Loopback AngularJS SDK provides client-side representation of the models and remote methods in the LoopBack server application. What you actually use is not MongoDB query (at least not directly). You are calling angular service which is calling remote method from persisted model on server. Loopback then translates your request to query using database connector. In your case this is MongoDB connector.

    That being said correct way to use find method in loopback angularjs sdk is:

      Feed.find({
          filter: {
            where: {
              or: [{accountId: "569a9fc898e6f58b0329eefc"}, {accountId: "569a9fa098e6f58b0329eefb"}]
            }
          }
        },
        function (feeds) {
            console.log(feeds); //query result is available in callback function
        });