Database Schema design for mongodb
so basically I am creating a project similar to shopify. I have users and each user can have one or more stores. There is a limited number of stores a user can have. For each store I assign a subdomain to my main domain, so I retrieve data using that subdomain that is basically the id of the store. So my question is: Should I create 2 collections (stores and users) and build a relationship between them. or Should I put a stores (array of objects) inside the each user document.
do you know?
how many words do you know
See also questions close to this topic
-
delete a table form a database using laravel command
i need to delete a database table using laravel artisan command . not like this command php artisan migrate:rollback --step=5
i need to create like this route or controller code .
Route::get('/clear/database', function () {
Artisan::call('cache:clear'); return redirect('/');
});
. i also try public function dd()
{ Schema::drop('table_name'); }
but it not working . gives me error like this SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (SQL: drop table
table_name
)no foreign key for the table . what should i do ?
thanks in advance!
-
How to bring data frame into single column from multiple columns in python
I have data format in these multiple columns. So I want to bring all 4 columns of data into a single column.
YEAR Month pcp1 pcp2 pcp3 pcp4 1984 1 0 0 0 0 1984 2 1.2 0 0 0 1984 3 0 0 0 0 1984 4 0 0 0 0 1984 5 0 0 0 0 1984 6 0 0 0 1.6 1984 7 3 3 9.2 3.2 1984 8 6.2 27.1 5.4 0 1984 9 0 0 0 0 1984 10 0 0 0 0 1984 11 0 0 0 0 1984 12 0 0 0 0
-
On the time function of database
When I use Kingbase database in Windows environment, I find that the time function returns the same value in the same transaction. How do I deal with it
-
How to projection fields for a dictionary (C#, MongdoDB)
I am trying my luck here, I have a model which is like the following
public class RowData : BaseBsonDefinition { . [BsonExtraElements] [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] public Dictionary<string, object> Rows { get; set; } = new(StringComparer.OrdinalIgnoreCase); . }
In result, the schema in the MongoDB looks like
{ "_id": { "$binary": { "base64": "HiuI1sgyT0OZmcgGUit2dw==", "subType": "03" } }, "c1": "AAA", "c8": "Fully Vac", "c10": "", }
Those c1, c8 and c10 fields are keys from the dictionary, my question is how to dynamic project those fields?
I tried
Builders<RowData>.Projection.Exclude(p => "c1")
It seems the MongoDB driver can not handle a value directly.
Anyone could point me in the correct direction?
Thanks,
-
Error message : MongoServerError: bad auth :Authentication failed
What is the reason behind this error? this code I am using to connect to DB.
const uri =`mongodb+srv://${process.env.DB_USER}:${process.env.DB_PASSWORD}@cluster0.xft2s.mongodb.net/myFirstDatabase?retryWrites=true&w=majority`;
-
In Mongo, If a document I'm saving "Prateek" then I don't want on the next create operation even the "prateek" or "praTEEK", etc is saved
//** If I'm adding a new document with the name: "India", then I don't want that the DB allow another name with the name: "INDIA", "india", "indIA", etc. I'm new and learning, help would be great!!**
// Controller
var Dinosaur = require('../models/dinosaurs'); //addDino module.exports.addDino = (req, res) => { var name = req.body.name; var type = req.body.type; var height = req.body.height; var weight = req.body.weight; var Period = req.body.Period; req.checkBody('name', 'Name is required').notEmpty(); var errors = req.validationErrors(); if (errors) return res.status(400).send({ message: 'Name is Required' }); else { let newDino = { name: name, type: type, height: height, weight: weight, Period: Period } Dinosaur.addDino(newDino, (err, result) => { if (err) { if (err.name) return res.status(409).send({ message: name + ' Already Exist' }); else if (err.url) return res.json({ status: false, error: { url: "Url already exist" }, message: err.url }); else return res.json(err, "Server Error"); } else { return res.status(200).send({ message: "Done" }); } }); } }
// Model
var mongoose = require('mongoose'); //dinosaur schema var DinosaurSchema = mongoose.Schema({ name: { type: String, unique: true }, type: { type: String }, height: { type: Number }, weight: { type: Number }, Period: { type: String } }); var Dinosaur = mongoose.model('dinosaur', DinosaurSchema); //add module.exports.addDino = (query, callback) => { Dinosaur.create(query, callback); }
// GetAll, Already Created a new document with the name "Brachiosaurus"
// > Create, a new create with the first letter lower case "brachiosaurus", Don't want it to be pushed.
-
Issues with building the service architecture
I need help in creating a good design for my microservice.
There is a certain data schema that is hierarchically related to each other:
- Company
- Licenses for the company (link to the company 1 to 1)
- Topic for devices (just as an identifier, some kind of general group to which devices belong. Link to the company many to one)
- The devices themselves (Linux, Windows, etc. Link to the topic many to one)
Now there is such a situation that there is a central database where all services go to the one database.
I had a task to add a new type of devices to item 4 (for example, Linux-based devices) and, accordingly, a new microservice and database so that everything was beautiful. And then the question arises, what are the popular approaches for data synchronization between 2 microservices?
It turns out that item 4 will be divided with items 1,2,3. If it were all within 1 db, I would just add a link in the tables, but how can I do this with two separate repositories? I can't imagine yet how this relationship can look in the database in principle with this approach and how to keep consistency between the data
-
It is good to create hybrid database?
I'm create a hybrid database with using PostgreSQL and MongoDb. The structure of this solution is that I wanted to save some data in relational tables and the rest in non-relational documents for the convenience of operating on this data.
Due to the fact that I have a many-to-many relationship (the only one in the application) between the user and the projects that he may have, I used the Postgres relational database to save them, because I decided that I should not look for relationality in MongoDB documents. For this reason, it saves the Users, Projects and UserProjectRElationship tables in the relational database. Everything else it needs is stored in mongodb, adding the appropriate identifiers to the resources they belong to (e.g. user or project id).
And now I have a question, is this a good solution for storing data in databases or should I focus on one database and save everything in one place?
-
Users review each other - SQL relationship design
I would like to know the best way of implementing a user review relationship using Sequelize. Each user can review another user's account. For example user A can review user B's account and user B can review user A's account. Each review will have a "comment, rating, user_id (the one who writes the review), reviewable_id (the target)".
So clearly, I will have two tables Users and Reviews but I cannot identify the right relationship between them and between the users. I know that each user can write many reviews and each review belongs to only one writer which means a one-to-many relationship but when I think of the Reviewable I get confused.
-
How to use "oneOf" in this schema?
I'd like to have either A or B, but not both (mutual exclusive.)
I have to use whatever is avaliable in Draft 3, even though it says 4 on the top. Reason being, when using array for "required", it throws an error that it can't convert an array to a boolean. If I remove arrays without putting that I'm using draft 4 [Newtonsoft.Json.Schema.Extensions]::IsValid does not validate. It returns "true" willy nilly.
Yes, I have to use an obsolete Newtonsoft.
{ "$schema": "http://json-schema.org/draft-04/schema#", "description": "", "type": "object", "additionalProperties": false, "properties": { "SearchCriteria": { "type": "array", "uniqueItems": true, "minItems": 1, "required": true, "items": { "type": "object", "additionalProperties": false, "properties": { "A": { "type": "string", "minLength": 1, "pattern": "^[^\\s]*$" }, "B": { "type": "array", "items": { "type": "string", "minLength": 1, "pattern": "^[^\\s]*$", "enum": ["One", "Two"] }, "minItems": 1 }, "C": { "type": "string", "required": true, "minLength": 2 }, "D": { "type": "array", "required": true, "items": { "type": "string" }, "minItems": 1, "uniqueItems": true } } } } } }
-
Update user role in postgresql
I would like to know how should I start to create schema in postgresql to update user role for a specific existing
user1 - existing team member, need to update the user role from PMO to team member
-
Did I import inetOrgPerson schema correctly for OpenLDAP on Alpine Linux?
I'm trying to import a user into OpenLDAP on Alpine Linux. Here's the LDIF that I named searchUser.ldif:
# Search account dn: uid=search,dc=home changetype: add objectClass: top objectClass: person objectClass: inetOrgPerson cn: search sn: search uid: search
The command I used to import it is:
ldapadd -x -D "cn=Manager,dc=home" -w supersecret -f searchUser.ldif
The error I get is:
ldap_add: Invalid syntax (21) additional info: objectClass: value #2 invalid per syntax
My understanding of this is the objectClasses are numbered, starting with 0, and that #2 indicates the problem is with inetOrgPerson.
I've done this successfully using OpenLDAP on Raspberry Pi OS (debian). However, I get the feeling the Debian package automates some configuration steps that the Alpine package does not. One of those steps I think Debian does during the package install is to import inetOrgPerson schema.
I've tried to do the schema import manually. Here are the steps I took prior to trying the LDIF import...
I scripted my install of OpenLDAP on Alpine, like so:
export DOMAIN="dc=home" echo "Installing packages..." apk add openldap openldap-back-mdb openldap-clients echo "Configuring for v2.3+ style slapd.d config directory..." install -m 755 -o ldap -g ldap -d /etc/openldap/slapd.d sed -i~ \ -e 's/^cfgfile=/#cfgfile=/' \ -e 's/^#cfgdir=.*/cfgdir=\"\/etc\/openldap\/slapd.d\"/' \ /etc/conf.d/slapd rm /etc/openldap/slapd.conf echo "Customizing for domain: ${DOMAIN}..." sed -i~ \ -e 's/\.la$/.so/' \ -e "s/dc=my-domain,dc=com/${DOMAIN}/" /etc/openldap/slapd.ldif echo "Importing configuration..." slapadd -n 0 -F /etc/openldap/slapd.d -l /etc/openldap/slapd.ldif chown -R ldap:ldap /etc/openldap/slapd.d/* echo "Configuring slapd service..." install -m 755 -o ldap -g ldap -d /var/lib/openldap/run service slapd start rc-update add slapd
The slapd service started and I could connect to it with command-line tools and from a client over port 389. So far, so good.
The next thing I did was to import schema for cosine and inetOrgPerson. I believe the Debian package did this automatically, because I don't recall having to do this previously.
Here's what I did on Alpine to import the schema:
slapadd -n 0 -F /etc/openldap/slapd.d -l /etc/openldap/schema/cosine.ldif slapadd -n 0 -F /etc/openldap/slapd.d -l /etc/openldap/schema/inetorgperson.ldif
There were no errors.
I then created an organization using the command
ldapadd -x -D "cn=Manager,dc=home" -w secret -f org.ldif
and this LDIF as org.ldif:dn: dc=home objectclass: dcObject objectclass: organization o: Home dc: home dn: cn=Manager,dc=home objectclass: organizationalRole cn: Manager
This too was successful.
I can also create organizational units with this LDIF:
# Organizational unit for users dn: ou=People,dc=home changetype: add objectClass: organizationalUnit ou: People # Organizational unit for groups. dn: ou=Groups,dc=home changetype: add objectClass: organizationalUnit ou: Groups
So I think my server is okay, but I may have done something wrong with the inetOrgPerson schema import that's causing the Invalid syntax (21) error.
Is the way I'm importing the inetOrgPerson schema correct? Is there a way to verify it?
-
Scaling structured, relational data
I've been reading about SQL vs. NoSQL databases, and I understand that Relational Databases are a good fit for relational data, and Non-Relational DBs scale better and thus make a good fit for these use cases.
My question is, what does one do when they have highly relational, structured data, AND they want to scale it significantly?
-
RavenDB Error: I can't access var store from a different class. Any Suggestions
RavenDB Error: var store isn't a global variable. How do I create a class that can use access documentstore? Any comments on why this code refuses to run is greatly appreciated
class Program { static void Main(string[] args) { var store = new DocumentStore { Urls = new[] { "http://localhost:8080" }, Database = "Tasks" }; store.Initialize(); } class OtherProgram using (var session = Store.OpenSession()) { var task = session.Load<Entity>(combinedInitial + email) //More code }