nosql

MongoDB get all embedded documents where condition is met

北城余情 提交于 2020-01-06 05:17:24
问题 I did this in my mongodb: db.teams.insert({name:"Alpha team",employees:[{name:"john"},{name:"david"}]}); db.teams.insert({name:"True team",employees:[{name:"oliver"},{name:"sam"}]}); db.teams.insert({name:"Blue team",employees:[{name:"jane"},{name:"raji"}]}); db.teams.find({"employees.name":/.*o.*/}); But what I got was: { "_id" : ObjectId("5ddf3ca83c182cc5354a15dd"), "name" : "Alpha team", "employees" : [ { "name" : "john" }, { "name" : "david" } ] } { "_id" : ObjectId(

Couchbase 4 beta “ORDER BY” performance

无人久伴 提交于 2020-01-06 01:30:16
问题 I have one question about performance of "ORDER BY" in Couchbase 4 Beta (Ubuntu 64bits). I create a Bucket "testing" and a primary index: CREATE PRIMARY INDEX `testing-idx` ON `testing` USING GSI; And a second index: CREATE INDEX testing_field_value_idx ON `testing`(field_value) USING GSI In my bucket I have items such as: { "type": "entry", "field_name": "field-testing", "field_value": "1 bla bla bla bla bla bla bla bla" }, { "type": "entry", "field_name": "field-testing", "field_value": "2

数据库介绍与分类

匆匆过客 提交于 2020-01-06 00:30:57
第1章 数据库介绍与分类 1.1 数据库介绍 什么是数据库 简单的说,数据库就是一个存放计算机数据的仓库,这个仓库是按照一定的数据结构(数据结构是指数据的组织形式或数据之间的联系)来对数据进行组织和存储的,我们可以通过数据库提供的多种方法来管理其中的数据。 1.2 数据库的种类 按照早期的数据库理论,比较流行的数据库模型有三种,分别为层次式数据库、网状数据库和关系型数据库。而在当今的互联网企业中,最常用的数据库模式主要有两种,即关系型数据库和非关系型数据库。 1.2.1 关系型数据库介绍 (1)关系型数据库由来 虽然网状数据库和层次数据库已经很好地解决了数据的集中和共享问题,但是在数据独立和抽象级别上仍有很大欠缺。用户在对这两种数据库进行存取时,仍然需要明确数据的存储结构,指出存取路径。而关系数据库就可以比较好地解决这些问题。 (2)关系型数据库介绍 关系型数据库模型是把复杂的数据结构归结为简单的二元关系(即二维表格形式)。在关系型数据库中,对数据的操作几乎全部建立在一个或多个关系表格上,通过这些关联的表格分类、合并、连接或选取等运算来实现数据的管理。 关系型数据库诞生距今已有40多年了,从理论产生到发展到实现产品,例如:常见的MySQL和Oracle数据库,oracle在数据库领域里上升到了霸主地位,形成每年高达数百亿美元的庞大产业市场,而MySQL也是不容忽视的数据库

Optimize array query match with operator $all in MongoDb

ⅰ亾dé卋堺 提交于 2020-01-05 15:05:30
问题 In a collection of 130k elements with the structure: { "tags": ["restaurant", "john doe"] } There are 40k documents with "restaurant" tag but only 2 with "john doe". So the next queries are different: // 0.100 seconds (40.000 objects scanned) {"tags": {$all: [/^restaurant/, /^john doe/]}} // 0.004 seconds (2 objects scanned) {"tags": {$all: [/^john doe/, /^restaurant/]}} It's there a way to optimize the query without sorting the tags in the client? The only way I can imagine now is putting

Querying Subdocument and Returning Matching Subdocument only

佐手、 提交于 2020-01-05 09:30:28
问题 cExample Mongo Document { "_id": ObjectId("5652e77f21b0f1f2692558a1"), "category": "clothing", "Brand": [ { "name": "Adidas", "key": "Adidas" }, { "name": "Reebok", "key": "Reebok" }, { "name": "Puma", "key": "Puma" } ], "Color": [ { "name": "Red", "key": "Red" }, { "name": "Green", "key": "Green" }, { "name": "Blue", "key": "Blue" } ] } Now I want to search for Brands where name is either Adidas or Puma. Other requerement is to return sub document only so I tried query given below find( {

Temporary Collection in MongoDB

我怕爱的太早我们不能终老 提交于 2020-01-05 09:07:40
问题 I can't understand this paragraph from mongodb MapReduce documentation (http://docs.mongodb.org/manual/applications/map-reduce/) - what Temporary Collection (optimisation?) is good for (business case, benefits etc)? Temporary Collection The map-reduce operation uses a temporary collection during processing. At completion, the map-reduce operation renames the temporary collection. As a result, you can perform a map-reduce operation periodically with the same target collection name without

Tags relationship in loopback 3

心已入冬 提交于 2020-01-05 05:32:09
问题 In Loopback how can I create tags? For example there are projects { id, name } and there are tags collection with the similar model Now the project needs to have multiple tags, and the same tag can be used in multiple projects. For example while creating a project, the user may type already existing tags, or new tags, and those should be added to the project. I can't find the exact relationship I need in the loopback framework. How do you do that? 回答1: TLDR CREATE TABLE ProjectTag (id AUTO

Firebase: How to structure data for the most shared posts in the last n days?

冷暖自知 提交于 2020-01-05 04:24:31
问题 Let's assume there is a blog and you would like to list the most liked or shared posts for today, the last 7 days and the last 30 days. The solution for today is rather easy: -mostSharedPostsForToday -2018-10-08 -$postId -numberOfShares Then the query would observe mostSharedPostsForToday/2018-10-08 for today's most shared posts ordered by child numberOfShares . But how to structure the data for the most shared posts in the past n days? One solution I can think of is to write a cloud function

Is SparkSQL RDBMS or NOSQL?

北慕城南 提交于 2020-01-05 04:04:06
问题 Recently, I was having a discussion with my friend over the features of SparkSQL when we came across this question. Are they ACID transactions? Does SparkSQL follow CAP theorem? I am a little new to this field, help me out. Thanks in advance. 回答1: SparkSQL is a query language and not a storage like Hive or MYSQL. Although it can register table which can be used by others, its only temporary. SparkSQL supports what the underlying databases support. 回答2: SparkSQL follows the Relational database

Converting simple MySQL database to a NoSQL solution

泪湿孤枕 提交于 2020-01-05 00:43:47
问题 I have a very small MySQL Database where the main table is about 300 records and I do add more occasionally. The table stores locations to files and some meta data for video assets that my users have access to. (movie title, path, keyframe name, movie name, file name, etc, etc) I wanted to move this table to an in-memory solution, but I am confused now-a-days as to that options there are and what is really the fastest, lightest weight, best bang for the buck. Redis? MongoDB? Something else?