nosql

Best practices for efficiently storing md5 hashes in MongoDB

浪尽此生 提交于 2019-12-11 01:04:42
问题 Assuming we have an md5 hash: With ruby: >Digest::MD5.hexdigest("ZZtop") => "d3e5c7c22df12b70e882f593432a3bdd" Possible field types: :type => String :type => Hash Which should I choose? 回答1: Use a String. A Hash in BSON refers to a key-value pair set. 回答2: In MongoDB, hash does not mean a cryptographic fingerprint (as in MD5 or SHA-1). It means hash as in hash table (a data structure that allows the storage of key-value pairs). You have to use a string to store a MD5 fingerprint. 回答3: String,

MongoDB - Why does the _id index not throwing an error on duplicate entries?

早过忘川 提交于 2019-12-10 23:34:01
问题 I'm completely new to NoSQL databases and I'm working currently with MongoDB. I'm trying to understand why the default _id index does not throw an error, when upserting a duplicate _id document. As stated in the docs _id is an unique index by default (although it doesn't show the unique flag here..) > db.foo.getIndexes(); [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.foo" } ] > So when upserting the document (started with an empty collection), if first inserts it and then

cloudant index: count number of unique users per time period

人走茶凉 提交于 2019-12-10 22:12:13
问题 A very similar post was made about this issue here. In cloudant, I have a document structure storing when users access an application, that looks like the following: {"username":"one","timestamp":"2015-10-07T15:04:46Z"} ---| same day {"username":"one","timestamp":"2015-10-07T19:22:00Z"} ---^ {"username":"one","timestamp":"2015-10-25T04:22:00Z"} {"username":"two","timestamp":"2015-10-07T19:22:00Z"} What I want to know is to count the # of unique users for a given time period. Ex: 2015-10-07 =

mongodb c# driver - inheritance, mappings and serialization issue

杀马特。学长 韩版系。学妹 提交于 2019-12-10 21:37:58
问题 I have following class hierarchy for object stored in mongodb (I store only Branch objects and Entities in their graph) public class Branch : Aggregate { public IEnumerable<LocalizableText> Description { get; set; } public ObjectId PartnerId { get; set; } public double Latitude { get; set; } public double Longitude { get; set; } public string Timetable { get; set; } public IEnumerable<Discount> Discounts { get; set; } public IEnumerable<Category> Categories { get; set; } public IEnumerable

How to accumulate results (with forEach?) in MongoDB?

喜你入骨 提交于 2019-12-10 21:21:26
问题 Suppose I want to search through a collection, scan the returned result set and return some transformation of it. I've tried the following code: db.my_collection.find({timestamp : {$gt: 1343032491799}}, {_id:0,sid:1}).limit(20).forEach(function(element) { print(element.sid); }) Ok, it worked well. To the question: how can I accumulate the results ( sid s) into an array instead of just printing them? Update : ruby-style one-liner is preferred (but not required) of course 回答1: Call toArray on

How to create “trigger” in MongoDB

╄→尐↘猪︶ㄣ 提交于 2019-12-10 20:30:04
问题 I would like of create a trigger where, to each subdocument inserted would increment in other collection a field, for generate a count of subdocuments that collection. I tried create a search using MapReduce, but for Milions of the Registries is very slow. Note: I use C#, but if you like show how to do in Bson, no problem. Extructure my collection public class Header { public Header() { Operation= new List<Operation>(); } public ObjectId Id { get; set; } public Int64 Code1 {get; set;} public

How to create TTL Index on long timestamp in MongoDB

自作多情 提交于 2019-12-10 19:51:43
问题 In my mongo database I have field timestamp which holds time of creation in timestamp ie: "timestamp": 1544029233021 I want to create TTL index on this field, but in docs example is done on "createdAt": new Date(), which is ISODate("2018-12-13T17:00:10.433Z") Is it possible to in any way to make TTL Index work on timestamp field? Because this doesnt work: db.coll.createIndex( { "timestamp": 1 }, { expireAfterSeconds: 3600 } ) 回答1: The documents aren't being expired because the timestamp value

Is ALLOW FILTERING in Cassandra for following query efficient?

怎甘沉沦 提交于 2019-12-10 19:37:09
问题 I have a table like this: CREATE TABLE IF NOT EXISTS Posts ( idObject int, objectType text, idParent uuid, id uuid, idResolution uuid, PRIMARY KEY ((idObject, objectType, idParent), id) ); Now have a look at the following query: SELECT * FROM POSTS WHERE idobject = 1 AND objectType = 'COURSE' AND idParent = 00000000-0000-0000-0000-000000000000 AND idResolution = 00000000-0000-0000-0000-000000000000 ALLOW FILTERING Now the Partition Key is completely known, so if I use ALLOW FILTERING is there

HBase基本介绍

别说谁变了你拦得住时间么 提交于 2019-12-10 19:33:45
1HBase基本介绍、 简介 hbase是bigtable的开源java版本。是 建立在hdfs之上 ,提供高可靠性、高性能、列存储、可伸缩、实时读写nosql的 数据库系统 。 它介于nosql和RDBMS之间,仅能通过主键(row key)和主键的range来检索数据,仅支持单行事务(可通过hive支持来实现多表join等复杂操作)。 主要用来存储结构化和半结构化的松散数据。 Hbase查询数据功能很简单,不支持join等复杂操作,不支持复杂的事务(行级的事务) Hbase中支持的数据类型:byte[] 与hadoop一样,Hbase目标主要依靠 横向扩展 ,通过不断增加廉价的商用服务器,来增加计算和存储能力。 HBase中的表一般有这样的特点: 大:一个表可以有上十亿行,上百万列 面向列:面向列(族)的存储和权限控制,列(族)独立检索。 稀疏:对于为空(null)的列,并不占用存储空间,因此,表可以设计的非常稀疏。 传统数据表 HBase的发展历程 HBase的原型是Google的BigTable论文,受到了该论文思想的启发,目前作为Hadoop的子项目来开发维护,用于支持结构化的数据存储。 官方网站:http://hbase.apache.org 2006年Google发表BigTable白皮书 2006年开始开发HBase 2008 HBase成为了

Distinct attribute value from Global Secondary Index in DynamoDB

社会主义新天地 提交于 2019-12-10 19:24:37
问题 How do we achieve the similar functionality of distinct keyword from SQL in Amazon DynamoDB? 回答1: dyanamo db is not support this kind of functionality, but you can achieve this in some ways (client side, lambda on dynamodb stream the updates another table with distinct values..) you can find a good answer here: Retrieve distinct values from the hash key - DynamoDB 来源: https://stackoverflow.com/questions/39512491/distinct-attribute-value-from-global-secondary-index-in-dynamodb