NoSQL Databases

154

Solutions

301

Contributors

A NoSQL database provides a mechanism for storage and retrieval of data which is modeled in means other than the tabular relations used in relational databases. Motivations for this approach include: simplicity of design, simpler "horizontal" scaling to clusters of machines and finer control over availability. The data structures used by NoSQL databases (e.g. key-value, wide column, graph, or document) are specified from those used by default in relational databases, making some operations faster in NoSQL. Sometimes the data structures used by NoSQL databases are also viewed as "more flexible" than relational database tables.

Share tech news, updates, or what's on your mind.

Sign up to Post

I have a products and category collection. I want to query both of them and send the data through one controller so I can display products and categories in the same view.

This seems to work but I am not sure if it is the correct way of doing it? If not, please could you you advise me on a more appropriate way.

exports.getIndex = (req, res, next) => {
  Product.find({ status: "approved" })
    .sort({ createdAt: -1 })
    .then(products => {
      Category.find({})
        .sort({ catName: 1 })
        .then(category => {
          res.render("shop/index", {
            pageTitle: "My home page",
            path: "/",
            prods: products,
            category: category
          });
        });
    })
    .catch(err => {
      console.log(err);
    });
};

Open in new window

0
OWASP: Threats Fundamentals
LVL 12
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Somebody has a good example autocomplete search nodejs, express, mongodb
0
mongodb SSL encryption with application makes slow.
Can somebody help on this
0
I am trying to count database records in mongoDB (using mongoose) where records have a status of pending and approved as well as rejected. So, I am basically trying to get a result where I can show a count of each and display it in my view ie:

Pending: 35
 Approved: 97
 Rejected: 12

And I want to hold these in variables that I can use in different places ie:

const pending = ....
const approved = ....
const rejected = .....

I have tried to use the aggregate function and run a loop which gets me all the data I need but I don't know how to actually get the data into the three variables like above.

    Product.aggregate([
        { $group: { _id: { status: "$status" }, totalStatus: { $sum: 1 } } }

    ])

Open in new window


The above code gives me back this (I have no rejected values yet)

[
    {
        _id: {
            status: 'pending'
        },
        totalStatus: 15
    },
    {
        _id: {
            status: 'approved'
        },
        totalStatus: 27
    }
  ]

Open in new window


I then ran a loop and restructured the data:

        .then(status => {
            for (const current of status) {
                const [status, total] = [current._id.status, current.totalStatus];
                console.log(status + ': ' + total);
            }
            next();
        })

Open in new window


That gives me:

pending: 15
approved: 27

But it still isn't what I actually want. I need to get those values into their own variables. How can I do that?
1
I am used to php/mysql where I would just join tables but mongoose seems to be a whole other beast.

I have a product schema and a user schema.

here is product:

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const productSchema = new Schema({
    title: {
        type: String,
        required: true
    },
    category: {
        type: String,
        required: true
    },
    image: {
        type: String,
        required: true
    },
    description: {
        type: String,
        required: true
    },
    userId: {
        type: Schema.Types.ObjectId,
        ref: 'User',
        required: true
    },
    address: {
        city: {type: String, required: true }
    },
    createdAt: {
        type: Date,
        default: Date.now
    },
});

module.exports = mongoose.model('Product', productSchema);

Open in new window


And the user:

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const userSchema = new Schema({
    firstName: {
        type: String,
        required: true
    },
    lastName:  {
        type: String,
        required: true
    },
    email: {
        type: String,
        required: true,
        index: true,
        unique: true
    },
    contactNo: {
        type: String,
        required: true
    },
    password:  {
        type: String,
        required: true
    },
    address: {
        city: {type: String, required: true },
    }
});

module.exports = mongoose.model('User', userSchema);

Open in new window


When I as the admin user want to see the users first name and last name for the added product (as well as that product informatioN) I would to 'join' the 'tables' and based on the UserID in the product schema get the first name and last name from the users schema.

I am trying to use .populate here but not sure if it's correct or efficient.

exports.getApprove = (req, res, next) => {
    const productId = req.params.productId;
    Product.findById(productId)
    .populate('userId', 'firstName', 'lastName')
    .then(product => {
        res.render('account/approve', {
            pageTitle: 'Approve Listing',
            path: '/accounts/approve',
            product: product
        });
    })
    .catch(err => {
        console.log(err);
    });
};

Open in new window


console.log(product.userId.firstName);

Open in new window


Just wondering if I am not meant to use .exec() or .execPopulate() here
0
I have only worked with php and mysql so am used to normalising my database and doing a lot of table joins etc. but I am moving over to node.js now and using mongoose with mongo DB and what I have gathered is that you shouldn't structure your db in the same way you would using php mysql. Apparently you should rather have a denormalised database. Could anyone give me an idea of where I could find a good example of this or possibly explain this in terms of an example? I have attached an image of a relational database setup I found on google and just wondered how the mongo db database would differ?
relational.png
0
How to create select the following records via Mongo DB query

Assume database has following rows

Pen/TEST/PO1/
Pen/PSO/QCD-Formats/QCD-file.pdf
Pen/PSO/QOD-Formats/QOD-F-29(00)_Stage 2.doc -
Pen/PSO/PDF/SFO/1.txt
Pen/PSO/2.txt  
Pen/QOD-F-23(00)_Stage 2.doc

1st Query to fetch the exact record matching the given folder path

ex:
user gives Pen/TEST/PO1/

expected result
Pen/TEST/PO1/

assume user gives: Pen/PSO/QOD-Formats/QOD-F-29(00)_Stage 2.doc

expected result:
Pen/PSO/QOD-Formats/QOD-F-29(00)_Stage 2.doc

2nd Query to fetch all the records matching the given folder path and it's files alone and not sub-folder's files

assume user gives: Pen/PSO/

expected result

Pen/PSO/QCD-Formats
Pen/PSO/QOD-Formats
Pen/PSO/PDF
Pen/PSO/2.txt  

Thanks.
0
I am trying to connect to a MongoDB database with asp.net core in C# with a userid and password.  Can anyone assist me in that respect?
0
Hello,

is it possible to access the collections, index without reading data on mongodb ?

Thank you

Best regards
0
How get the last document inserted in mongoDB

Im using nodejs, express mongoose
0
Become a CompTIA Certified Healthcare IT Tech
LVL 12
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

i would look like ro analyse/describe data that is big over 300,000,000 rows do you python can be able to help me do this. how efficiently can i do thos
1
A new API requires us to receive about 45kb of information per row (record) and save this in a database, we see think about 700GB of data will be added PER year. The table is simple with 50 columns or fields. We are not sure if this is a job for MongoDB or MySQL. The setup must be able to scale horizontally, table will also be queried and searchable . About 1000 transactions per second.
0
I have a system in elasticsearch collecting performance metrics from my network. The space occupied is a lot, and I need to know how to optimize disk space. I have the idea that the project consists of having detailed samples of the last time (for example, one or two weeks). Beyond that time you can have historical samples, but with less detail.
I need to start organizing how to carry this forward.
0
Does MariaDB & MongoDB (I mean the Enterprise Edition) have
commercial support (just like RedHat Linux has while CentOS
is user-community support only)?

Concern is if there are security vulnerabilities (which may result
in data leaks) or DB corruption/integrity.  I've heard of banks
using MariaDB but I'm not sure if they house critical data but
I certainly would not want to house critical data on databases
that are non-commercially supported or even if it's commercially
supported by vendors with low track record (I deem Oracle &
MS as good-track record DB vendors).

I think MongoDB is a non-relational (ie network) DB.

Concern is if a database is hosting critical data, user-community
support is not non-committal & patches are not released as
regularly as commercially-supported softwares, though it's
noted MS release patches monthly, much more than any other
commercial vendors
0
redis used as cache data in at some point if we want to persist to SQL/No SQL is there a straight forward way?
0
Hello,

How kill session through opsmanager ?

Thank you


Regards
0
Sir,

I need a help on  Cassandra data model, is it a better way to design our table data structure   so that our bulk reads would be faster
please  suggest


CREATE TABLE IF NOT EXISTS screening_counts_by_location_year (
      total_screened_0_6 counter,
      male_0_6 counter,
      female_0_6 counter,

      total_screened_6_18 counter,
      male_6_18 counter,
      female_6_18 counter,

      total_screened counter,
      total_male counter,
      total_female counter,

      awc_screened counter,
      school_screened counter,
      college_screened counter,

      year varchar,

      location varchar,
      parent varchar,
      PRIMARY KEY((parent, location, year)));



CREATE TABLE IF NOT EXISTS screening_counts_by_location_year_mht (
      total_screened_0_6 counter,
      male_0_6 counter,
      female_0_6 counter,

      total_screened_6_18 counter,
      male_6_18 counter,
      female_6_18 counter,

      total_screened counter,
      total_male counter,
      total_female counter,

      awc_screened counter,
      school_screened counter,
      college_screened counter,
       mht_id varchar,
      year varchar,
      location varchar,
      parent varchar,
      PRIMARY KEY((parent, location, year), mht_id))
      WITH CLUSTERING ORDER BY (mht_id DESC);




CREATE TABLE rbsk_andr_v2.beneficiaryrecord (
    visitationpointtype text,
    reportdate date,
    zone text,
    district text,
    revenuedivision text,
    mandal text,
    village text,
    visitationpointcode text,
    universalid text,
    attendance text,
0
Dear Experts,

we have  back end application running on Cassandra and which has all our transaction data but we have a static data available in mysql
but i would like to know  if I would like to have queries between tables across two databases for the joins how that can be achieved.

Thanks
Roy...
0
Connection Error: No Mongos proxy available.

Environment: Node.js, MongoDB, Mongoose

Start.js
const mongoose = require('mongoose');


mongoose.connect(process.env.DATABASE,  { useNewUrlParser: true })
mongoose.Promise = global.Promise;
mongoose.connection
  .on('connected', () => {
    console.log(`Mongoose connection open on ${process.env.DATABASE}`);
  })
  .on('error', (err) => {
    console.log(`Connection error: ${err.message}`);
  });

.env file

DATABASE=mongodb://username:DBpassword@player-shard-00-00-1cmur.mongodb.net:27017,player-shard-00-01-1cmur.mongodb.net:27017,player-shard-00-02-1cmur.mongodb.net:27017
0
JavaScript Best Practices
LVL 12
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

How to use more than one percentage sign in queries in OrientDB?

For example : select from MyNode where MyNodeText.toLowerCase() like '%text1%text2%'
This does not work
0
I want to write a init script to stop and start the MongoDB.
0
Hi,
i am currently working on the task of Data Migration from 1 cassandra cluster table to another cassandra cluster table using spark batch job.

i need a spark code for reading data from one cassandra cluster table and to process it in spark and then write results onto another existing cassandra cluster table.
0
I know there's a ton of questions around date/time storage and formatting, but I'm struggling to get the right approach. My app is a Node.js app with Express using mongoose with a MongoDB backend. I'm using moment.js to format my date/times.

The schema in question looks like:

const stateSchema = new mongoose.Schema({
  changed: {
    type: Date,
    default: new Date()
  }
});

Open in new window

Based on the docs, I was expecting the date to be stored in UTC by default, but instead I see this:
changed: 2018-08-15 17:26:14.499

Open in new window

I'm displaying the date/time with something like (pug):

p= `Changed: ${moment(state.changed).format('MMMM Do YYYY, h:mm:ss a')}`

Open in new window

On localhost, the app shows "August 15th 2018, 5:26:14 pm" but on the hosted Heroku app I get "August 15th 2018, 10:26:14 pm." I am expecting "August 15th 2018, 5:26:14 pm" because I'm opening the Heroku app in the same timezone, but it looks like it's giving me the server timezone.

What should I do to make sure the date/time shows up in the client's local timezone?
0
HI,
Need experts view on the following line  -
Most NoSQL solutions however are built with the assumption that the data does not fit on a single machine and hence have sharding builtin.

Is it that noSQL solutions have easier or better sharding capabilites than relational databased like mysql ?

And should one use noSQL always in case of sharding ?

Thanks
0
Hi,
suppose i have a mysql table  with rows (originalUrl : varchar(500) , shortUrl : varchar(10))
The queries that will be executed on this table will mostly be
1. select * from table where shortUrl = X
2. insert into table (originalUrl, shortUrl)

So there should be an index on shortUrl to speed this up.

I have the following question -
1. What exactly the index table will store ?
My understanding is index table will store items like - (shortUrl, pointerToDisk) // where pointerToDisk will locate exactly the place in disk where the row is stored.

2. Where is index table stored ?
Is it always stored in Disk or memory ?

3. What is the size of index table exceeds that of RAM ?
In this case the full index table will never be in RAM and so how will queries like select * from table where shortUrl = x execute
Will a part of index table be pulled out everytime to check the location ?

4. In case where this table is very huge say 3 TB. How big will index table be...

5. If index table is larger than size of RAM and since then the queries will take a lot of time. Is there a better alternative ?? Like using noSQL database. or storing data in two machines splitting them rather than on one machine ?

Thanks
0

NoSQL Databases

154

Solutions

301

Contributors

A NoSQL database provides a mechanism for storage and retrieval of data which is modeled in means other than the tabular relations used in relational databases. Motivations for this approach include: simplicity of design, simpler "horizontal" scaling to clusters of machines and finer control over availability. The data structures used by NoSQL databases (e.g. key-value, wide column, graph, or document) are specified from those used by default in relational databases, making some operations faster in NoSQL. Sometimes the data structures used by NoSQL databases are also viewed as "more flexible" than relational database tables.

Top Experts In
NoSQL Databases
<
Monthly
>