How can I obtain services to MongoDB Realm App? - mongodb

Hi there fellow coders,
Maybe one of you could bridge the gap I seem to be having.
I'm new to Mongo and tried to set up a database. Then created a Realm App.
According to the documentation (https://docs.mongodb.com/realm/web/mongodb/), I need to link a data source(https://docs.mongodb.com/realm/mongodb/link-a-data-source/).
Having done that, the doco seems to indicate I should be able to use the line:
const mongo = app.services.mongodb("<atlas service name>");
However, I get an error saying "Cannot read property 'mongodb' of undefined". Obviously, it's because there is no services against app.
I tried looking this up online, but found no answers. Hoping someone experienced could guide me as to what is missing or what I'm clearly not seeing.
TIA!

Are you using MongoDB 4.4?
Are you using MongoDB Atlas? Realm sync does not work for on-premises MongoDB.
If you're using all that, I would go to https://realm.mongodb.com and click "Create a New App" and then the screen that shows up, you pick the cluster to connect with and that's the service. (or choose the 'we'll create one for you' option).

Services are not included in realm-web code if it’s installed via npm
Services and functions are now available on User instance
const mongo = user.mongoClient("<atlas service name>");
const db = mongo.db("<my-database-name>");
const collection = db.collection("<my-collection-name>");'

The default name is mongodb-atlas:
const mongo = app.services.mongodb("mongodb-atlas");

Related

not getting mongoDB collections via retool query

I've connected mongoDB as a resource for retool and created a query for it in my retool app, but the queries don't really work for me. The action query "listCollections" goes through but it gets wrong info on those collections but the action query "find" and other actions report the error message "Collection names cannot be empty". Where is the problem, I can't figure it out!
Thank you for the attention! Hope anyone can reach out and help
I had the same issue and it started at the same time as yours, this worked for me try doing the following:
1- Goto MongoDB->"Data Access" and provide your user "admin" status
2- Open Retool Query library add a new Resource using the connection string of user you just made admin.
3- Test the connection and save it.
4- Refresh retool and try again.
Hope it helps :-)

Metadata Does Not seem to update correctly

Our company uses Hasura Cloud with a React js front end with gQlApollo.
I recently added a new column "myString" to type "myType" in our database and was able to successfully update our Hasura Cloud instance by resetting the Metadata within settings.
I know this worked because when I use the API on Hasura Cloud I am able to successfully return the new column and its value.
I also see that the graphQl Engine metadata is green as shown here status of graphQl engine metadata
The problem is when I try to query this new column locally it seems that this metadata is not successfully being updated there. I have no local hasura core so the suggestion online to preform a hasura metadata clear does not apply to me.
I have tried:
resetting my browser history
run hasura init and reset the meta data after which did not fix my problem
Any idea how I can accomplish resetting the metadata locally?
Solved my issue! It was because I had not changed the permissions for the newly created column in cloud.hasura.io. Now that I have added that it works without needing to reset the Metadata at all.

PouchDB Extension not showing second database

I’ve only just started using PouchDB (with Ionic), so I’m still working on wrapping my head around everything and getting it all set up (all my experience is in MySQL).
I have a simple Ionic app working with PouchDB and some basic CRUD abilities, now I’m trying to visualise what I’m doing using the PouchDB Extension for Chrome. So far so good, I click a “+” button to add an item to a list and the new database shows up under “Databases” in the PouchDB Extension.
Now I’m doing the exact same thing for a second database, and it’ll put my newly created items in a separate list, all seems to be good, I can edit and delete these items as well, just like in the first database. But this second database won’t show up in the PouchDB Extension and for the life of me I can’t figure out why, I’m doing exactly the same as with the first database.
This is part of my code for the first database:
function initDB() {
_db = new PouchDB('threads');
};
function addThread(thread) {
return $q.when(_db.post(thread));
};
And then this is what I'm doing for the second one:
function initDB() {
_db = new PouchDB('categories');
};
function addCategory(category) {
return $q.when(_db.post(category));
};
Btw: This is the tutorial I've followed to get the PouchDB part of my Ionic app working. (Basically just followed part of it twice to get the second database working)
Edit: So I just found the "application" tab in Chrome's developer tools (again, I come from MySQL databases, never worked with local storage before). I can view the Web SQL databases there and both my databases do show up there, but still only the first one is shown in the PouchDB extension :(
Edit 2: Alright this is turning into a whole different problem. I was aware that the PouchDB extension doesn't support the websql adapter, I thought PouchDB defaulted to IndexedDB but apparently idb isn't available in my Chrome installation? If I do the following to explicitly say I want to use the IndexedDB adapter:
_db = new PouchDB('threads', {adapter: 'idb'});
I get the following error: Error: Invalid Adapter: idb
If open the page in either Firefox or Chrome Canary I get no errors at all, and after adding the PouchDB inspector to Canary everything works as I want it to. I did update Chrome to the latest version (Version 53.0.2785.101 (64-bit)).
Any ideas as to why my regular Chrome installation doesn't support IndexedDB? (it should right, or am I going nuts? (I feel like I am))
Edit 3: Ok even though I feel like I'm talking to myself I'll continue posting my findings. Since the problems seemed to lie with my Google Chrome installation I reinstalled it, problem solved. If someone has some idea of what went wrong I'm all ears, until then I'm finally continuing on my project haha..
I ran into same issues, chrome extention doesnt support websql, only index db.
https://github.com/angular-pouchdb/angular-pouchdb/issues/63
you can try this to get the DB sizing etc.
db.info().then(function (resp) {
//resp will contain disk_size
})

how do I connect mongoDB to a Dataiku dataset?

This question is about Dataiku DSS .
I'm having trouble opening a mongoDB collection and connecting it as a dataset in Dataiku.
There's an option of using Python script but I'm not sure how to do it.
This is a very late answer but the following page explains how to connect to mongoDB in Dataiku DSS:
https://www.dataiku.com/learn/guide/connecting/dss-and-mongodb.html
You have to be administrator of the instance.
The main steps are:
Go to Administration->Connections
New connection->MongoDB
Fill the Host, Database name, User, Password fields
Grant the appropriate rights (probably write access, and specific groups).
Click the Test button to make sure everything is ok, then save it.

Sails Wateline find with mongodb Object Id not working

I've an application with sails.js and mongodb.
The sails rest api works fine for create. It also works fine when I access it as "http://localhost:1337/student" but not working when finding a specific document with id "http://localhost:1337/student/54e57a98469768d40df7fb24".
The object id in db is stored as _id : ObjectId("54e57a9e469768d40df7fb25").
I also tried to update record in Controller but that also seems to be NOT working:
Student.update({id:Student.mongo.objectId(req.body.id)},{is_active:0}).exec(function(err, data){
............
});
Any help will be appreciated.
Thanks.
I do notice your ids are different between your URL and the mongo paste, so make sure that is on. Also I'd recommend installing the postman packaged app in the google chrome store, its really nice for doing rest work. If you watch the sailscasts videos by nathanirl on YouTube you'll see some nice examples of what it can do.
Also make sure your blueprints.js in config file is setup with. Actions, shortcuts and rest set to true