简体   繁体   English

如何从couchdb中的文档列出数据类型

[英]how to list data types from a document in couchdb

Is there any opprtunity to list all data types of a document in couchdb like string, object,integer ? 是否有任何机会在couchdb中列出文档的所有数据类型,如字符串,对象,整数?

I'm using only curl with a Windows machine. 我只使用curl和Windows机器。

If you desire to use purely CURL on the client side you will need to create a design document to answer your query. 如果您希望在客户端使用纯粹的CURL,则需要创建一个设计文档来回答您的查询。 The design document would have the following mapping function: 设计文档具有以下映射功能:

function(doc) {
    function obj_to_types( obj ){
        var types = {};
        Object.keys( obj ).forEach( function( k ) {
            var prop = obj[k];
            var type = typeof prop;
            var typeValue;
            if( type == "object" ){
                typeValue = obj_to_types( prop );
            }else{
                typeValue = type;
            }
            types[k] =typeValue;
        });
        return types;
    }
    emit(doc.id, obj_to_types( doc ));
}

This will produce output for each document such as: 这将为每个文档生成输出,例如:

{
_id: "string",
_rev: "string",
format: {
  0: "number",
  1: "number",
  2: "number"},
etc: "string"
}

CouchDB is using JSON, and JSON does have a limited set of datatypes, described here: http://json.org/ CouchDB使用JSON,JSON确实有一组有限的数据类型,如下所述: http//json.org/

Any higher level datatype like "DateTime" or such, are a matter of format and not standardized. 任何更高级别的数据类型,如“DateTime”等,都是格式问题而非标准化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM