What is the convention for creating applications users in MongoDB? - mongodb

I am trying to create a users model for my application sign in with Mongoose / MongoDB. Based on how I see it when I deploy to Atlas or Mlab, it auto generates a users collection but for the purpose of database authentication - like this user has read access, write access, admin, etc. What is the convention for creating application users? Do I also use the same users collection but add additional schema properties or do I make a different one altogether like app_users. Thanks!

Are you using the test or admin database? You should create a new database for your application. When you create a new database it will not come with any predefined collections or such, so you can start blank (which is what I assume you want?).
You don't need to explicitly create a new database. Just point your driver to a database name you want for your app. Or in the mongo CLI type use myAppDb and you can start adding collections there.
More details here https://docs.mongodb.com/manual/mongo/#working-with-the-mongo-shell

Related

How do I add MongoDB Realm App Users to Atlas collection?

I'm working on a SwiftUI app that connects to a MongoDB Atlas database (hosted) which is populated and managed by a server. I've created a Realm for my SwiftUI app, and can sucessfully create a user and log-in, but I'm having trouble connecting the created user (found in App Users in the Realm UI) to a user document in my database's User collection. Whats the proper way to do this? Do I need to manually create a user in the collection for any new app users?
#jostell13 - REALM users are not ATLAS DATABASE USERS.
However, this does not mean that REALM users need their own collection for any new app.
When you create a realm app, you specify the ATLAS cluster it is associated with. There are multiple ways to do this - I'll go over two. SDK, Functions
https://docs.mongodb.com/realm/sdk/swift/examples/read-and-write-data/#read---write-data---swift-sdk
https://docs.mongodb.com/realm/sdk/swift/data-types/collections/#collections-are-live
The SDK provides LIVE collections, which is a really awesome capability. If LIVE collections, and things like real-time notifications, live updating objects, lazy-loading objects etc are not a requirement, you could also consider functions.
(Credit to #Jay for bringing up SDK > Functions)
https://docs.mongodb.com/realm/functions/
const plants = context.services.get("mongodb-atlas").db("example").collection("plants");
const plant = await plants.findOne();
return JSON.stringify(plant);
Functions can be called from the REALM app, or you could even create things like HTTPS endpoints so you can interact with functions using simple HTTP requests. https://docs.mongodb.com/realm/endpoints/
The best part about functions is - DEPENDENCIES! You can literally use almost any npm module as a dependency for your functions! (There are some limitations, but this featureset will only be improving in the future)
https://docs.mongodb.com/realm/functions/add-external-dependencies/
While I got a lot of useful info from the responses here, the solution I found was not mentioned.
The correct way to do this is still to do a manual copy of data from the Realm to the database via a triggered function.

Multi Firestore database

I am creating a mobile app , and this mobile app works currently with one google fire store database.
I want to see this app to more than one customer and I don't want to make a collection for each customer.
Instead I want to open a new database.
I know that I need to import the JSON file for each database.
My Question:
Can I tell the app to use database one then if you login with another
account use database 2?
There is only a single Firestore database instance per Firebase project. There is (currently) no way to add additional Firestore database instances to a project.
So that means you'd have to have a separate project for each user. That part is technically feasible for databases, as you can dynamically create a FirebaseApp instance with the configuration data for the signed in user. The problem is that you need to first sign in the user (which requires that you already have a FirebaseApp instance for the project that this user is registered on.
I'd highly recommend reconsidering why you want to create a separate Firestore instance for each user, as creating user-specific sub-collections is by far the simplest way to implement a multi-user application on Firestore.

default user mongodb with django_restframework_mongoengine?

I am using django_restframework_mongoengine in a project and I need to know if it exists, and how to use the default user of mongodb. As well as the user of django with its ORM, I have some possibility with an ODM?

Working in Heroku, can I share a collection in Mongodb/mongolab(mlab)?

In Heroku, I have 2 apps. One client app(uses coffeescript and mongoose) and one admin app(uses javascript and mongoskin).
I would like to share one collection within these both apps, but cannot find out how to. I don't know if "sharding collections" is the route I should be researching to share a collection?...I would like some help figuring out a way to share a collection between 2 databases and 2 different heroku apps, or if it is possible.
I found some links on sharing databases, but I would like to share only collections within the databases. Here are some of the links I found, but haven't tested correctly since it deals with Meteor apps, not Heroku:
How can I share MongoDB collections between Meteor apps?,
DDP between two servers doesn't reconnect, Connect two Meteor applications using DDP
Of the 2 Heroku apps, one of them is the "owner" of the database for the collection you wish to share and is already pre-configured with the MONGODB_URI connection string for the database add-on. You would need to manually configure the 2nd Heroku app with the connection string for the database containing the collection you wish to share:
https://devcenter.heroku.com/articles/mongolab#connecting-to-existing-mlab-deployments-from-heroku
Note that this setup would share the entire database between the 2 add-ons. If you need restrict it to just a collection, you would need to create a database user for the 2nd Heroku app that only has access to the collection in question.
http://docs.mlab.com/connecting/#users
https://docs.mongodb.com/v3.0/core/security-user-defined-roles/
User defined role admin needs to be done through a client like the mongo shell - mLab's UI does not support them.

Azure Mobile Services - Connect to Existing Database

I'd like to create a Azure Mobile Service (.NET) that reads / writes from an existing database that is being used by an MVC 5 app. I've been trying, without luck, for the better part of a day to make this happen through the few examples that exist on the internet.
I've just now come across this SO post where Carlos Figueira says that a mobile service creates a new schema with the same name as the service name and all access is done via that schema and the user that has permission to that schema. If this is the case, how will I be able to have my mobile service connect to an existing table, if it always creates new tables in the new schema?
Also, I'm getting the impression that mobile services using .NET is much happier if I don't attempt to connect to an existing DB. Is this the case?
Azure Mobile Services will only work with tables in the new schema (with the service name). In order to work with an existing database, you need to transfer the tables to this schema, and then you will need to rename all your PK columns to "id" (lowercase). Once you have done that, the tables still don't show up in the Data tab in the management interface, but you can 'add' them and then it will connect and you can work with your existing data.
See this link for full walkthrough: http://www.strathweb.com/2012/12/using-existing-database-with-azure-mobile-services/