• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

While MongoDb provides querying capability how it works out when it encounters unstructured data?

 
Ranch Foreman
Posts: 2085
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MongoDb is a document oriented database which provides querying capability (somewhat like SQL). But MongoDb is used for storing unstructured data. So, what happens when it encounters unstructured data while querying? I mean this is easier to understand for structured data but what how does this work out in case of unstructured data?
thanks
 
Saloon Keeper
Posts: 22807
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find that question to be impossible to understand.  
 
Monica Shiralkar
Ranch Foreman
Posts: 2085
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:I find that question to be impossible to understand.  


Thanks.
MongoDb is used for unstructured data. MongoDb provides querying capability.

I am trying to understand that how are the above 2 sentences true at the same time.

What I can understand : MongoDb is used in cases where there are tons of documents to be stored (e.g JSONs) and we need some querying capability (although not comparable to sql) and this data can be unstructured. I can understand that querying capability in case of  unstructured data but how does querying work out when data is unstructured.
 
Tim Holloway
Saloon Keeper
Posts: 22807
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Structure is not required to do a query. If I have a collection of PDF documents and I want to know which ones were authored by George Chatterjee after January 15 of this past year, the author name and date (among other things) are named attributes of a PDF document. Since they are named, software can scan the set of documents and return only the ones whose attributes meet the query criteria.

MongoDB is essentially the same thing, except that it can store more than just PDF data.

What you cannot do, of course, in a NoSQL database is JOIN operations, since a NoSQL database isn't composed of a set of rigidly-formatted tables.
 
Monica Shiralkar
Ranch Foreman
Posts: 2085
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:Structure is not required to do a query. If I have a collection of PDF documents and I want to know which ones were authored by George Chatterjee after January 15 of this past year, the author name and date (among other things) are named attributes of a PDF document. Since they are named, software can scan the set of documents and return only the ones whose attributes meet the query criteria.

MongoDB is essentially the same thing, except that it can store more than just PDF data.

What you cannot do, of course, in a NoSQL database is JOIN operations, since a NoSQL database isn't composed of a set of rigidly-formatted tables.



Say we have JSON documents such that JSONs have customerId, speed, tirePressure, coolantTemperature. With unstructured data, what I understand is that some JSON would not be having say coolantTemperature and some will be having. If my understanding of unstructured data is correct, then how does querying work on in such case? One thing which I think may be happening is that whichever is absent is JSON may be taken as NULL in the query.  How does querying work out in such cases?

thanks
 
Tim Holloway
Saloon Keeper
Posts: 22807
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MongoDB documents and JSON documents are 2 different things. Yes, you could store JSON strings as attributes in a MongoDB document, but querying the attributes of JSON itself isn't something that I think that MongoDB itself does, nor is MongoDB designed primarily as a repository for JSON documents, although you could import or export JSON to MongoDB, at least within limits.

I suggest you read the MongoDB documents on how it searches for and returns MongoDB documents:

https://docs.mongodb.com/manual/tutorial/query-documents/
 
Ranch Hand
Posts: 31
3
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MongoDB stores data as "documents" where a "document" is basically a JSON document (strictly speaking, it's BSON, which is Binary JSON and offers stricter typing and parsing features).  BSON also allows you to store binary objects a bit like you can store BLOBs in a SQL database.  But mostly, you can think of your MongoDb documents as JSON, because that's mostly how you interact with them.  A MongoDB "document" has nothing to do with e.g. a PDF or Word document, unless you want to store the PDF as a binary object, I guess.

MongoDB queries are based on a JSON query language, where you specify your query as a JSON document. This query language is pretty powerful and flexible, and there are also MongoDB query APIs for most programming languages.  The MongoDB Aggregation query framework is a more functional approach to query definition, where you define a query as a pipeline of operations, a bit like in some Big Data platforms such as Apache Spark.

By default, MongoDB is schema-less: you store your documents in "collections", which are like RDBMS tables, but these do not enforce a schema.  This means you are responsible for ensuring that the documents (records) in a collection are consistent with each other.  So you could say that MongoDB stores semi-structured data i.e. JSON is structured with fields and values, but it isn't necessarily the same structure for every document (record) in your collection (table).

(Personally, I think this is one reason why MongoDB was so popular with web developers in its early days: web devs often don't like working with or thinking about RDBMS data models, so the NoSQL approach meant they didn't have to care about their data model, as they could just throw everything into the same MongoDB collection.  Kind of like that one drawer in the kitchen where all the random stuff ends up.  But then one day, you need to find specific items in your big collection, and then life becomes ... interesting.  .)

Luckily, you can tell your query to look for documents where a given field is null, or where the field does not exist, so there are ways to deal with inconsistent JSON structures in your collection.

Nowadays, MongoDB offers more support for data modelling, including schema validation.  Eventually, even NoSQL databases rediscover SQL...  

Here is a simple mapping between SQL and MongoDB concepts.

Anyway, MongoDB University offers lots of free online courses in MongoDB, and these are a great way to learn the key features of the database and query language.

 
Monica Shiralkar
Ranch Foreman
Posts: 2085
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
Monica Shiralkar
Ranch Foreman
Posts: 2085
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:

What you cannot do, of course, in a NoSQL database is JOIN operations, since a NoSQL database isn't composed of a set of rigidly-formatted tables.



I have been knowing this that it does not support JOINs but the below link from MongoDb is talking about joins:

https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/

 
reply
    Bookmark Topic Watch Topic
  • New Topic