lunes, 4 de diciembre de 2017

Sublime3 Template con configuración ESLint, Git




La idea es clonar de git el repositorio y tener una carpeta de trabajo inicial para trabajar con
es SublimeText3 con características configuradas de ESLint y Git. con la idea de desarrollar en javascript es6 y node.js

Para esto tenemos que tener instalado
- node.js.
- SublimeText 3, con control de paquetes instalado y los siguientes paquetes instalados:
    - Babel
    - ESLint
    - Package Control
    - SublimeGit
    - SublimeLinter
    - SublimeLinter-contrib-eslint

Ya preparado Sublime con los paquetes necesarios, solo tenemos que dar en una carpeta donde clonaremos de git, el templete para desarrollar con javascript es6 el siguiente comando

>git clone https://github.com/jalbertomr/sublime3ESLint.git

Cloning into 'sublime3ESLint'...
remote: Counting objects: 5702, done.
remote: Compressing objects: 100% (4479/4479), done.
remote: Total 5702 (delta 979), reused 5702 (delta 979), pack-reused 0
Receiving objects: 100% (5702/5702), 4.45 MiB | 412.00 KiB/s, done.
Resolving deltas: 100% (979/979), done.
Checking connectivity... done.
Checking out files: 100% (6097/6097), done.

Abrimos sublime y observamos una simple estructura de carpetas y archivos, es de notar los siguientes archivos:

.eslintrc
   Este tiene la configuración de comportamiento de eslint. que tiene la siguiente forma
module.exports = {
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": "eslint:recommended",
    "parser": "babel-eslint",
    //"extends": "rallycoding"
    "parserOptions": {
        "ecmaVersion": 6
    },
    "rules": {
        "no-console": 0
    }
    /*"rules": {
        "indent": [
            "error",
            4
        ],
        "linebreak-style": [
            "error",
            "windows"
        ],
        "quotes": [
            "error",
            "single"
        ],
        "semi": [
            "error",
            "always"
        ]
    }*/
};
   Este archivo podemos cambiar las reglas de ESLint descomentando la linea de "extends: rallycoding" y comentando "extends":"eslint:recommended".
  Este archivo se pude generar con el comando >eslint --init Interactivamente no consultará opciones, y generara el archivo el cual se puede customizar posteriormente.


packages.json
   Archivo de configuración de node.js, creado con el comando >npm init que interactivamente
   nos ira preguntando sobre la configuración de nuestro proyecto, este archivo deberá ser
   reconfigurado según las características del nuevo proyecto.

Asi nos queda la funcionalidad de ESLint


y con la funcionalidad Git se ve así.


Solo falta cambiarle el nombre del proyecto, de carpeta, ajustar el package.json a necesidad del proyecto.

Listo :)

jueves, 30 de noviembre de 2017

React + Webpack HMR (Hot Module Reload)


En package.json modificamos reactmon en su parametro para agregar --ignore components, asi ignorara los cambios en el subdirectorio components
y no nos mostrara que esta reainicializando el server.
..."scripts": {
    "test": "\"echo \\\"Error: test no especificado\\\" && exit 1\"",
    "serve": "nodemon server/server.js --ignore components"
  },
...

Cargamos el babel-hmre "hot module reload"
npm install babel-preset-react-hmre --save-dev



C:\Users\Bext\Desktop\react-todo-list_kweiberth>npm install babel-preset-react-hmre --save-dev
react-todo-list@1.0.0 C:\Users\Bext\Desktop\react-todo-list_kweiberth
+-- babel-preset-react-hmre@1.1.1
| +-- babel-plugin-react-transform@2.0.2
| +-- react-transform-catch-errors@1.0.2
| +-- react-transform-hmr@1.0.4
| | +-- global@4.3.2
| | | +-- min-document@2.19.0
| | | | `-- dom-walk@0.1.1
| | | `-- process@0.5.2
| | `-- react-proxy@1.1.8
| |   `-- react-deep-force-update@1.1.1
| `-- redbox-react@1.5.0
|   +-- error-stack-parser@1.3.6
|   | `-- stackframe@0.3.1
|   +-- object-assign@4.1.1
|   +-- prop-types@15.6.0
|   | +-- fbjs@0.8.16
|   | | +-- isomorphic-fetch@2.2.1
|   | | | +-- node-fetch@1.7.3
|   | | | | +-- encoding@0.1.12
|   | | | | `-- is-stream@1.1.0
|   | | | `-- whatwg-fetch@2.0.3
|   | | `-- setimmediate@1.0.5
|   | `-- object-assign@4.1.1
|   `-- sourcemapped-stacktrace@1.1.7
|     `-- source-map@0.5.6
`-- UNMET DEPENDENCY webpack@^1.12.13

npm WARN babel-loader@6.4.1 requires a peer of webpack@1 || 2 || ^2.1.0-beta || ^2.2.0-rc but none was installed.

se integra a webpack.config.js
...
module: {
        loaders: [
          {
            test: /\.js$/,
            loader: 'babel-loader',
            exclude: /node_modules/,
            query: {
                presets: ['react' , 'es2015', 'react-hmre']
            }
          }
        ]
    }...

Y se integran en el mismo archivo los plugins

import webpack from 'webpack';

module.exports = ...
...
    plugins: [
        new webpack.optimize.OccurrenceOrderPlugin(),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin()
    ],
    module: { ...
   
Para que el bundle.js se genere automaticamente cuando se detecta un cambio, en el archivo server/server.js debemos
integrar el archivo webpack.config.js para que el servidor pueda regenerar el bundle.js.

import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';

var compiler = webpack(config);

app.use(webpackDevMiddleware(compiler, {noinfo: true, publicPath: config.output.publicPath})));
app.use(webpackHotMiddleware(compiler));


- instalamos los paquetes que acabamos de integrar al codigo
C:\Users\Bext\Desktop\react-todo-list_kweiberth>npm install --save-dev webpack-dev-middleware webpack-hot-middleware
react-todo-list@1.0.0 C:\Users\Bext\Desktop\react-todo-list_kweiberth
+-- UNMET DEPENDENCY webpack@^1.12.13
+-- webpack-dev-middleware@1.12.2
| +-- memory-fs@0.4.1
| | +-- errno@0.1.4
| | | `-- prr@0.0.0
| | `-- readable-stream@2.3.3
| |   +-- core-util-is@1.0.2
| |   +-- isarray@1.0.0
| |   +-- process-nextick-args@1.0.7
| |   +-- string_decoder@1.0.3
| |   `-- util-deprecate@1.0.2
| +-- mime@1.6.0
| `-- time-stamp@2.0.0
`-- webpack-hot-middleware@2.21.0
  +-- ansi-html@0.0.7
  +-- html-entities@1.2.1
  `-- querystring@0.2.0

npm WARN babel-loader@6.4.1 requires a peer of webpack@1 || 2 || ^2.1.0-beta || ^2.2.0-rc but none was installed.
npm WARN webpack-dev-middleware@1.12.2 requires a peer of webpack@^1.0.0 || ^2.0.0 || ^3.0.0 but none was installed.


- Se agrega en entry : 'webpack-hot-middleware/client' en webpack.config.js

- Necesitamos instalar webpack globalmente
npm install -g webpack

C:\Users\Bext\Desktop\react-todo-list_kweiberth>npm install -g webpack
C:\Users\Bext\AppData\Roaming\npm\webpack -> C:\Users\Bext\AppData\Roaming\npm\node_modules\webpack\bin\webpack.js
C:\Users\Bext\AppData\Roaming\npm
`-- webpack@3.9.1

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\webpack\node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

- instalamos el webpack con npm install --save-dev webpack por que no aparecia en el subdirectorio
node_modules

- Ahora ya que tenemos instalado el hot module reload, lo probamos,  hacemos un cambio en el archivo  components/App.js y al salvarlo, la consola del servidor nos manda
webpack: Compiling...
webpack building...
webpack built dadb7df9fadea33f0c99 in 4035ms
Hash: dadb7df9fadea33f0c99
Version: webpack 1.15.0
Time: 4035ms
                               Asset      Size  Chunks             Chunk Names
                           bundle.js   2.81 MB       0  [emitted]  main
0.01d71f219328f9ec9028.hot-update.js   5.21 kB       0  [emitted]  main
01d71f219328f9ec9028.hot-update.json  36 bytes          [emitted]
chunk    {0} bundle.js, 0.01d71f219328f9ec9028.hot-update.js (main) 1.01 MB [rendered]
    [0] multi main 40 bytes {0}
    [1] ./~/node-libs-browser/~/process/browser.js 5.42 kB {0}
    [2] ./~/fbjs/lib/invariant.js 1.51 kB {0}
    [3] ./~/react/lib/Object.assign.js 1.26 kB {0}
    [4] ./~/fbjs/lib/warning.js 1.77 kB {0}
    [5] ./~/fbjs/lib/ExecutionEnvironment.js 1.09 kB {0}
    [6] ./~/react/lib/ReactMount.js 36.8 kB {0}
    [7] ./~/react/lib/ReactElement.js 8.07 kB {0}
    [8] ./~/react/lib/ReactPerf.js 2.51 kB {0}
...
  [338] ./~/stackframe/stackframe.js 3.48 kB {0}
  [339] ./~/strip-ansi/index.js 161 bytes {0}
  [340] (webpack)-hot-middleware/client-overlay.js 2.21 kB {0}
  [341] (webpack)-hot-middleware/client.js 7.35 kB {0}
  [342] (webpack)-hot-middleware/process-update.js 4.33 kB {0}
webpack: Compiled successfully.

Y automaticamente nuesta pagina refleja el cambio.


Una vez en produccion el HMR no es necesario integrarlo al proyecto.

Fin de Archivo

React + Webpack Instalación

 
Este laboratorio se basa en el Webinar de Kurt Weiberth llamado React + Redux + WebPack
https://www.youtube.com/watch?v=CAZZN1gOjoI&index=3&list=PLQDnxXqV213JJFtDaG0aE9vqvp6Wm7nBg

Para esto partimos de una instalacion limpia a la cual le iremos instalando los paquetes necesarios según se vayan requiriendo, con la excepción de que ya tenemos instaldo node.js v6.11.4.
consideremos agregar las siguientes rutas al PATH, esto será necesario según la versión de node.js
 %appdata%\npm
%ProgramFiles%\nodejs

- Clonamos el Repo de git  ya que este contiene una estructura particular de directorios sobre la que se desarrollara el proyecto.
  Solo para mostrar la estructura de directorios y archivos iniciales, abriremos el subdirectorio donde este el proyecto con Netbeans y crearemos un nuevo proyecto Node.js Application with existing Sources. no utilizaremos Netbeans para correr el laboratorio.



- Instalamos sublime, ya que utilizaremos ese editor.
  Le intalamos el plugin esLint

  Sublime menu ->preference->package control->install package->esLint

- Instalamos React y React-dom

C:\Users\Bext\Desktop\react-todo-list_kweiberth>npm install --save react react-dom
react-todo-list@1.0.0 C:\Users\Bext\Desktop\react-todo-list_kweiberth
+-- react@0.14.9
| +-- envify@3.4.1
| | +-- jstransform@11.0.3
| | | +-- base62@1.2.1
| | | +-- commoner@0.10.8
| | | | +-- commander@2.12.2
| | | | +-- detective@4.6.0
| | | | | +-- acorn@5.2.1
| | | | | `-- defined@1.0.0
| | | | +-- glob@5.0.15
| | | | | +-- inflight@1.0.6
| | | | | | `-- wrappy@1.0.2
| | | | | +-- inherits@2.0.3
| | | | | +-- minimatch@3.0.4
| | | | | | `-- brace-expansion@1.1.8
| | | | | |   +-- balanced-match@1.0.0
| | | | | |   `-- concat-map@0.0.1
| | | | | +-- once@1.4.0
| | | | | `-- path-is-absolute@1.0.1
| | | | +-- graceful-fs@4.1.11
| | | | +-- iconv-lite@0.4.19
| | | | +-- mkdirp@0.5.1
| | | | | `-- minimist@0.0.8
| | | | +-- private@0.1.8
| | | | +-- q@1.5.1
| | | | `-- recast@0.11.23
| | | |   +-- ast-types@0.9.6
| | | |   +-- esprima@3.1.3
| | | |   `-- source-map@0.5.7
| | | +-- esprima-fb@15001.1.0-dev-harmony-fb
| | | +-- object-assign@2.1.1
| | | `-- source-map@0.4.4
| | |   `-- amdefine@1.0.1
| | `-- through@2.3.8
| `-- fbjs@0.6.1
|   +-- core-js@1.2.7
|   +-- loose-envify@1.3.1
|   | `-- js-tokens@3.0.2
|   +-- promise@7.3.1
|   | `-- asap@2.0.6
|   +-- ua-parser-js@0.7.17
|   `-- whatwg-fetch@0.9.0
`-- react-dom@0.14.9

- Instalamos WebPack
C:\Users\Bext\Desktop\react-todo-list_kweiberth>npm install -g webpack
C:\Users\Bext\AppData\Roaming\npm\webpack -> C:\Users\Bext\AppData\Roaming\npm\node_modules\webpack\bin\webpack.js

> uglifyjs-webpack-plugin@0.4.6 postinstall C:\Users\Bext\AppData\Roaming\npm\node_modules\webpack\node_modules\uglifyjs-webpack-plugin
> node lib/post_install.js

C:\Users\Bext\AppData\Roaming\npm
`-- webpack@3.8.1
  +-- acorn@5.2.1
  +-- acorn-dynamic-import@2.0.2
  | `-- acorn@4.0.13
  +-- ajv@5.5.0
  | +-- co@4.6.0
  | +-- fast-deep-equal@1.0.0
  | +-- fast-json-stable-stringify@2.0.0
  | `-- json-schema-traverse@0.3.1
  +-- ajv-keywords@2.1.1
  +-- async@2.6.0
  | `-- lodash@4.17.4
  +-- enhanced-resolve@3.4.1
  | +-- graceful-fs@4.1.11
  | `-- object-assign@4.1.1
  +-- escope@3.6.0
  | +-- es6-map@0.1.5
  | | +-- d@1.0.0
  | | +-- es5-ext@0.10.37
  | | +-- es6-iterator@2.0.3
  | | +-- es6-set@0.1.5
  | | +-- es6-symbol@3.1.1
  | | `-- event-emitter@0.3.5
  | +-- es6-weak-map@2.0.2
  | +-- esrecurse@4.2.0
  | `-- estraverse@4.2.0
  +-- interpret@1.1.0
  +-- json-loader@0.5.7
  +-- json5@0.5.1
  +-- loader-runner@2.3.0
  +-- loader-utils@1.1.0
  | +-- big.js@3.2.0
  | `-- emojis-list@2.1.0
  +-- memory-fs@0.4.1
  | +-- errno@0.1.4
  | | `-- prr@0.0.0
  | `-- readable-stream@2.3.3
  |   +-- core-util-is@1.0.2
  |   +-- inherits@2.0.3
  |   +-- isarray@1.0.0
  |   +-- process-nextick-args@1.0.7
  |   +-- safe-buffer@5.1.1
  |   `-- util-deprecate@1.0.2
  +-- mkdirp@0.5.1
  | `-- minimist@0.0.8
  +-- node-libs-browser@2.1.0
  | +-- assert@1.4.1
  | +-- browserify-zlib@0.2.0
  | | `-- pako@1.0.6
  | +-- buffer@4.9.1
  | | +-- base64-js@1.2.1
  | | `-- ieee754@1.1.8
  | +-- console-browserify@1.1.0
  | | `-- date-now@0.1.4
  | +-- constants-browserify@1.0.0
  | +-- crypto-browserify@3.12.0
  | | +-- browserify-cipher@1.0.0
  | | | +-- browserify-aes@1.1.1
  | | | | `-- buffer-xor@1.0.3
  | | | +-- browserify-des@1.0.0
  | | | | `-- des.js@1.0.0
  | | | `-- evp_bytestokey@1.0.3
  | | |   `-- md5.js@1.3.4
  | | |     `-- hash-base@3.0.4
  | | +-- browserify-sign@4.0.4
  | | | +-- bn.js@4.11.8
  | | | +-- browserify-rsa@4.0.1
  | | | +-- elliptic@6.4.0
  | | | | +-- brorand@1.1.0
  | | | | +-- hash.js@1.1.3
  | | | | +-- hmac-drbg@1.0.1
  | | | | +-- minimalistic-assert@1.0.0
  | | | | `-- minimalistic-crypto-utils@1.0.1
  | | | `-- parse-asn1@5.1.0
  | | |   `-- asn1.js@4.9.2
  | | +-- create-ecdh@4.0.0
  | | +-- create-hash@1.1.3
  | | | +-- cipher-base@1.0.4
  | | | +-- ripemd160@2.0.1
  | | | | `-- hash-base@2.0.2
  | | | `-- sha.js@2.4.9
  | | +-- create-hmac@1.1.6
  | | +-- diffie-hellman@5.0.2
  | | | `-- miller-rabin@4.0.1
  | | +-- pbkdf2@3.0.14
  | | +-- public-encrypt@4.0.0
  | | +-- randombytes@2.0.5
  | | `-- randomfill@1.0.3
  | +-- domain-browser@1.1.7
  | +-- events@1.1.1
  | +-- https-browserify@1.0.0
  | +-- os-browserify@0.3.0
  | +-- path-browserify@0.0.0
  | +-- process@0.11.10
  | +-- punycode@1.4.1
  | +-- querystring-es3@0.2.1
  | +-- stream-browserify@2.0.1
  | +-- stream-http@2.7.2
  | | +-- builtin-status-codes@3.0.0
  | | +-- to-arraybuffer@1.0.1
  | | `-- xtend@4.0.1
  | +-- string_decoder@1.0.3
  | +-- timers-browserify@2.0.4
  | | `-- setimmediate@1.0.5
  | +-- tty-browserify@0.0.0
  | +-- url@0.11.0
  | | +-- punycode@1.3.2
  | | `-- querystring@0.2.0
  | +-- util@0.10.3
  | | `-- inherits@2.0.1
  | `-- vm-browserify@0.0.4
  |   `-- indexof@0.0.1
  +-- source-map@0.5.7
  +-- supports-color@4.5.0
  | `-- has-flag@2.0.0
  +-- tapable@0.2.8
  +-- uglifyjs-webpack-plugin@0.4.6
  | `-- uglify-js@2.8.29
  |   +-- uglify-to-browserify@1.0.2
  |   `-- yargs@3.10.0
  |     +-- camelcase@1.2.1
  |     +-- cliui@2.1.0
  |     | +-- center-align@0.1.3
  |     | | +-- align-text@0.1.4
  |     | | | +-- longest@1.0.1
  |     | | | `-- repeat-string@1.6.1
  |     | | `-- lazy-cache@1.0.4
  |     | +-- right-align@0.1.3
  |     | `-- wordwrap@0.0.2
  |     `-- window-size@0.1.0
  +-- watchpack@1.4.0
  | `-- chokidar@1.7.0
  |   +-- anymatch@1.3.2
  |   | +-- micromatch@2.3.11
  |   | | +-- arr-diff@2.0.0
  |   | | | `-- arr-flatten@1.1.0
  |   | | +-- array-unique@0.2.1
  |   | | +-- braces@1.8.5
  |   | | | +-- expand-range@1.8.2
  |   | | | | `-- fill-range@2.2.3
  |   | | | |   +-- is-number@2.1.0
  |   | | | |   +-- isobject@2.1.0
  |   | | | |   `-- randomatic@1.1.7
  |   | | | |     +-- is-number@3.0.0
  |   | | | |     | `-- kind-of@3.2.2
  |   | | | |     `-- kind-of@4.0.0
  |   | | | +-- preserve@0.2.0
  |   | | | `-- repeat-element@1.1.2
  |   | | +-- expand-brackets@0.1.5
  |   | | | `-- is-posix-bracket@0.1.1
  |   | | +-- extglob@0.3.2
  |   | | +-- filename-regex@2.0.1
  |   | | +-- kind-of@3.2.2
  |   | | | `-- is-buffer@1.1.6
  |   | | +-- object.omit@2.0.1
  |   | | | +-- for-own@0.1.5
  |   | | | | `-- for-in@1.0.2
  |   | | | `-- is-extendable@0.1.1
  |   | | +-- parse-glob@3.0.4
  |   | | | +-- glob-base@0.3.0
  |   | | | `-- is-dotfile@1.0.3
  |   | | `-- regex-cache@0.4.4
  |   | |   `-- is-equal-shallow@0.1.3
  |   | |     `-- is-primitive@2.0.0
  |   | `-- normalize-path@2.1.1
  |   |   `-- remove-trailing-separator@1.1.0
  |   +-- async-each@1.0.1
  |   +-- glob-parent@2.0.0
  |   +-- is-binary-path@1.0.1
  |   | `-- binary-extensions@1.11.0
  |   +-- is-glob@2.0.1
  |   | `-- is-extglob@1.0.0
  |   +-- path-is-absolute@1.0.1
  |   `-- readdirp@2.1.0
  |     +-- minimatch@3.0.4
  |     | `-- brace-expansion@1.1.8
  |     |   +-- balanced-match@1.0.0
  |     |   `-- concat-map@0.0.1
  |     `-- set-immediate-shim@1.0.1
  +-- webpack-sources@1.1.0
  | +-- source-list-map@2.0.0
  | `-- source-map@0.6.1
  `-- yargs@8.0.2
    +-- camelcase@4.1.0
    +-- cliui@3.2.0
    | +-- string-width@1.0.2
    | | +-- code-point-at@1.1.0
    | | `-- is-fullwidth-code-point@1.0.0
    | |   `-- number-is-nan@1.0.1
    | +-- strip-ansi@3.0.1
    | | `-- ansi-regex@2.1.1
    | `-- wrap-ansi@2.1.0
    |   `-- string-width@1.0.2
    +-- decamelize@1.2.0
    +-- get-caller-file@1.0.2
    +-- os-locale@2.1.0
    | +-- execa@0.7.0
    | | +-- cross-spawn@5.1.0
    | | | +-- lru-cache@4.1.1
    | | | | +-- pseudomap@1.0.2
    | | | | `-- yallist@2.1.2
    | | | +-- shebang-command@1.2.0
    | | | | `-- shebang-regex@1.0.0
    | | | `-- which@1.3.0
    | | |   `-- isexe@2.0.0
    | | +-- get-stream@3.0.0
    | | +-- is-stream@1.1.0
    | | +-- npm-run-path@2.0.2
    | | | `-- path-key@2.0.1
    | | +-- p-finally@1.0.0
    | | +-- signal-exit@3.0.2
    | | `-- strip-eof@1.0.0
    | +-- lcid@1.0.0
    | | `-- invert-kv@1.0.0
    | `-- mem@1.1.0
    |   `-- mimic-fn@1.1.0
    +-- read-pkg-up@2.0.0
    | +-- find-up@2.1.0
    | | `-- locate-path@2.0.0
    | |   +-- p-locate@2.0.0
    | |   | `-- p-limit@1.1.0
    | |   `-- path-exists@3.0.0
    | `-- read-pkg@2.0.0
    |   +-- load-json-file@2.0.0
    |   | +-- parse-json@2.2.0
    |   | | `-- error-ex@1.3.1
    |   | |   `-- is-arrayish@0.2.1
    |   | +-- pify@2.3.0
    |   | `-- strip-bom@3.0.0
    |   +-- normalize-package-data@2.4.0
    |   | +-- hosted-git-info@2.5.0
    |   | +-- is-builtin-module@1.0.0
    |   | | `-- builtin-modules@1.1.1
    |   | +-- semver@5.4.1
    |   | `-- validate-npm-package-license@3.0.1
    |   |   +-- spdx-correct@1.0.2
    |   |   | `-- spdx-license-ids@1.2.2
    |   |   `-- spdx-expression-parse@1.0.4
    |   `-- path-type@2.0.0
    +-- require-directory@2.1.1
    +-- require-main-filename@1.0.1
    +-- set-blocking@2.0.0
    +-- string-width@2.1.1
    | +-- is-fullwidth-code-point@2.0.0
    | `-- strip-ansi@4.0.0
    |   `-- ansi-regex@3.0.0
    +-- which-module@2.0.0
    +-- y18n@3.2.1
    `-- yargs-parser@7.0.0
      `-- camelcase@4.1.0

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\webpack\node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

- Instalamos Express
C:\Users\Bext\Desktop\react-todo-list_kweiberth>npm install -save express
react-todo-list@1.0.0 C:\Users\Bext\Desktop\react-todo-list_kweiberth
`-- express@4.16.2
  +-- accepts@1.3.4
  | +-- mime-types@2.1.17
  | | `-- mime-db@1.30.0
  | `-- negotiator@0.6.1
  +-- array-flatten@1.1.1
  +-- body-parser@1.18.2
  | +-- bytes@3.0.0
  | +-- http-errors@1.6.2
  | | `-- setprototypeof@1.0.3
  | `-- raw-body@2.3.2
  +-- content-disposition@0.5.2
  +-- content-type@1.0.4
  +-- cookie@0.3.1
  +-- cookie-signature@1.0.6
  +-- debug@2.6.9
  | `-- ms@2.0.0
  +-- depd@1.1.1
  +-- encodeurl@1.0.1
  +-- escape-html@1.0.3
  +-- etag@1.8.1
  +-- finalhandler@1.1.0
  | `-- unpipe@1.0.0
  +-- fresh@0.5.2
  +-- merge-descriptors@1.0.1
  +-- methods@1.1.2
  +-- on-finished@2.3.0
  | `-- ee-first@1.1.1
  +-- parseurl@1.3.2
  +-- path-to-regexp@0.1.7
  +-- proxy-addr@2.0.2
  | +-- forwarded@0.1.2
  | `-- ipaddr.js@1.5.2
  +-- qs@6.5.1
  +-- range-parser@1.2.0
  +-- safe-buffer@5.1.1
  +-- send@0.16.1
  | +-- destroy@1.0.4
  | `-- mime@1.4.1
  +-- serve-static@1.13.1
  +-- setprototypeof@1.1.0
  +-- statuses@1.3.1
  +-- type-is@1.6.15
  | `-- media-typer@0.3.0
  +-- utils-merge@1.0.1
  `-- vary@1.1.2

- Probamos que corra nuestro servidor

C:\Users\Bext\Desktop\react-todo-list_kweiberth>node server/server.js
Express server listening on port 3000

- Instalamos nodemon

C:\Users\Bext\Desktop\react-todo-list_kweiberth>npm install -g nodemon
C:\Users\Bext\AppData\Roaming\npm\nodemon -> C:\Users\Bext\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.js
C:\Users\Bext\AppData\Roaming\npm
`-- nodemon@1.12.1
  +-- chokidar@1.7.0
  | +-- anymatch@1.3.2
  | | +-- micromatch@2.3.11
  | | | +-- arr-diff@2.0.0
  | | | | `-- arr-flatten@1.1.0
  | | | +-- array-unique@0.2.1
  | | | +-- braces@1.8.5
  | | | | +-- expand-range@1.8.2
  | | | | | `-- fill-range@2.2.3
  | | | | |   +-- is-number@2.1.0
  | | | | |   +-- isobject@2.1.0
  | | | | |   +-- randomatic@1.1.7
  | | | | |   | +-- is-number@3.0.0
  | | | | |   | | `-- kind-of@3.2.2
  | | | | |   | `-- kind-of@4.0.0
  | | | | |   `-- repeat-string@1.6.1
  | | | | +-- preserve@0.2.0
  | | | | `-- repeat-element@1.1.2
  | | | +-- expand-brackets@0.1.5
  | | | | `-- is-posix-bracket@0.1.1
  | | | +-- extglob@0.3.2
  | | | +-- filename-regex@2.0.1
  | | | +-- kind-of@3.2.2
  | | | | `-- is-buffer@1.1.6
  | | | +-- object.omit@2.0.1
  | | | | +-- for-own@0.1.5
  | | | | | `-- for-in@1.0.2
  | | | | `-- is-extendable@0.1.1
  | | | +-- parse-glob@3.0.4
  | | | | +-- glob-base@0.3.0
  | | | | `-- is-dotfile@1.0.3
  | | | `-- regex-cache@0.4.4
  | | |   `-- is-equal-shallow@0.1.3
  | | |     `-- is-primitive@2.0.0
  | | `-- normalize-path@2.1.1
  | |   `-- remove-trailing-separator@1.1.0
  | +-- async-each@1.0.1
  | +-- glob-parent@2.0.0
  | +-- inherits@2.0.3
  | +-- is-binary-path@1.0.1
  | | `-- binary-extensions@1.11.0
  | +-- is-glob@2.0.1
  | | `-- is-extglob@1.0.0
  | +-- path-is-absolute@1.0.1
  | `-- readdirp@2.1.0
  |   +-- graceful-fs@4.1.11
  |   +-- readable-stream@2.3.3
  |   | +-- core-util-is@1.0.2
  |   | +-- isarray@1.0.0
  |   | +-- process-nextick-args@1.0.7
  |   | +-- safe-buffer@5.1.1
  |   | +-- string_decoder@1.0.3
  |   | `-- util-deprecate@1.0.2
  |   `-- set-immediate-shim@1.0.1
  +-- debug@2.6.9
  | `-- ms@2.0.0
  +-- es6-promise@3.3.1
  +-- ignore-by-default@1.0.1
  +-- lodash.defaults@3.1.2
  | +-- lodash.assign@3.2.0
  | | +-- lodash._baseassign@3.2.0
  | | | `-- lodash._basecopy@3.0.1
  | | +-- lodash._createassigner@3.1.1
  | | | +-- lodash._bindcallback@3.0.1
  | | | `-- lodash._isiterateecall@3.0.9
  | | `-- lodash.keys@3.1.2
  | |   +-- lodash._getnative@3.9.1
  | |   +-- lodash.isarguments@3.1.0
  | |   `-- lodash.isarray@3.0.4
  | `-- lodash.restparam@3.6.1
  +-- minimatch@3.0.4
  | `-- brace-expansion@1.1.8
  |   +-- balanced-match@1.0.0
  |   `-- concat-map@0.0.1
  +-- ps-tree@1.1.0
  | `-- event-stream@3.3.4
  |   +-- duplexer@0.1.1
  |   +-- from@0.1.7
  |   +-- map-stream@0.1.0
  |   +-- pause-stream@0.0.11
  |   +-- split@0.3.3
  |   +-- stream-combiner@0.0.4
  |   `-- through@2.3.8
  +-- touch@3.1.0
  | `-- nopt@1.0.10
  |   `-- abbrev@1.1.1
  +-- undefsafe@0.0.3
  `-- update-notifier@2.3.0
    +-- boxen@1.2.2
    | +-- ansi-align@2.0.0
    | +-- camelcase@4.1.0
    | +-- cli-boxes@1.0.0
    | +-- string-width@2.1.1
    | | +-- is-fullwidth-code-point@2.0.0
    | | `-- strip-ansi@4.0.0
    | |   `-- ansi-regex@3.0.0
    | +-- term-size@1.2.0
    | | `-- execa@0.7.0
    | |   +-- cross-spawn@5.1.0
    | |   | +-- lru-cache@4.1.1
    | |   | | +-- pseudomap@1.0.2
    | |   | | `-- yallist@2.1.2
    | |   | +-- shebang-command@1.2.0
    | |   | | `-- shebang-regex@1.0.0
    | |   | `-- which@1.3.0
    | |   |   `-- isexe@2.0.0
    | |   +-- get-stream@3.0.0
    | |   +-- is-stream@1.1.0
    | |   +-- npm-run-path@2.0.2
    | |   | `-- path-key@2.0.1
    | |   +-- p-finally@1.0.0
    | |   `-- strip-eof@1.0.0
    | `-- widest-line@1.0.0
    |   `-- string-width@1.0.2
    |     +-- code-point-at@1.1.0
    |     +-- is-fullwidth-code-point@1.0.0
    |     | `-- number-is-nan@1.0.1
    |     `-- strip-ansi@3.0.1
    |       `-- ansi-regex@2.1.1
    +-- chalk@2.3.0
    | +-- ansi-styles@3.2.0
    | | `-- color-convert@1.9.1
    | |   `-- color-name@1.1.3
    | +-- escape-string-regexp@1.0.5
    | `-- supports-color@4.5.0
    |   `-- has-flag@2.0.0
    +-- configstore@3.1.1
    | +-- dot-prop@4.2.0
    | | `-- is-obj@1.0.1
    | +-- make-dir@1.1.0
    | | `-- pify@3.0.0
    | +-- unique-string@1.0.0
    | | `-- crypto-random-string@1.0.0
    | `-- write-file-atomic@2.3.0
    |   +-- imurmurhash@0.1.4
    |   `-- signal-exit@3.0.2
    +-- import-lazy@2.1.0
    +-- is-installed-globally@0.1.0
    | +-- global-dirs@0.1.1
    | | `-- ini@1.3.5
    | `-- is-path-inside@1.0.0
    |   `-- path-is-inside@1.0.2
    +-- is-npm@1.0.0
    +-- latest-version@3.1.0
    | `-- package-json@4.0.1
    |   +-- got@6.7.1
    |   | +-- create-error-class@3.0.2
    |   | | `-- capture-stack-trace@1.0.0
    |   | +-- duplexer3@0.1.4
    |   | +-- is-redirect@1.0.0
    |   | +-- is-retry-allowed@1.1.0
    |   | +-- lowercase-keys@1.0.0
    |   | +-- timed-out@4.0.1
    |   | +-- unzip-response@2.0.1
    |   | `-- url-parse-lax@1.0.0
    |   |   `-- prepend-http@1.0.4
    |   +-- registry-auth-token@3.3.1
    |   | `-- rc@1.2.2
    |   |   +-- deep-extend@0.4.2
    |   |   +-- minimist@1.2.0
    |   |   `-- strip-json-comments@2.0.1
    |   `-- registry-url@3.1.0
    +-- semver-diff@2.1.0
    | `-- semver@5.4.1
    `-- xdg-basedir@3.0.0

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\nodemon\node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

- Ahora corremos ya con nodemon con el comando
>npm run serve









Esto  por que tenemos en packaje.json
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "serve": "nodemon server/server.js --ignore components"
  },

- No da esto de salida y corriendo OK.

> react-todo-list@1.0.0 serve C:\Users\Bext\Desktop\react-todo-list_kweiberth
> nodemon server/server.js --ignore components

[nodemon] 1.12.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server/server.js`
Express server listening on port 3000

- Como Webpack esta instalado glabalmente podemos ejecutarlo como
>webpack --config webpack.config.js






Pero antes necesitamos instalar otros paquetes que se requieren para hacer el bundle, estos son

babel-loader
babel-core
babel-preset-react
babel-preset-es2015

Se siguen las instrucciones del sitio de Babel



 Esto para que nos genere un solo archivo llamado bundle.js

C:\Users\Bext\Desktop\react-todo-list_kweiberth>npm install --save-dev babel-loader babel-core
react-todo-list@1.0.0 C:\Users\Bext\Desktop\react-todo-list_kweiberth
+-- babel-core@6.26.0
| +-- babel-code-frame@6.26.0
| | +-- chalk@1.1.3
| | | +-- ansi-styles@2.2.1
| | | +-- escape-string-regexp@1.0.5
| | | +-- has-ansi@2.0.0
| | | | `-- ansi-regex@2.1.1
| | | +-- strip-ansi@3.0.1
| | | `-- supports-color@2.0.0
| | `-- esutils@2.0.2
| +-- babel-generator@6.26.0
| | +-- detect-indent@4.0.0
| | | `-- repeating@2.0.1
| | |   `-- is-finite@1.0.2
| | |     `-- number-is-nan@1.0.1
| | +-- jsesc@1.3.0
| | +-- source-map@0.5.7
| | `-- trim-right@1.0.1
| +-- babel-helpers@6.24.1
| +-- babel-messages@6.23.0
| +-- babel-register@6.26.0
| | +-- core-js@2.5.1
| | +-- home-or-tmp@2.0.0
| | | +-- os-homedir@1.0.2
| | | `-- os-tmpdir@1.0.2
| | `-- source-map-support@0.4.18
| |   `-- source-map@0.5.7
| +-- babel-runtime@6.26.0
| | +-- core-js@2.5.1
| | `-- regenerator-runtime@0.11.0
| +-- babel-template@6.26.0
| +-- babel-traverse@6.26.0
| | +-- globals@9.18.0
| | `-- invariant@2.2.2
| +-- babel-types@6.26.0
| | `-- to-fast-properties@1.0.3
| +-- babylon@6.18.0
| +-- convert-source-map@1.5.1
| +-- json5@0.5.1
| +-- lodash@4.17.4
| +-- slash@1.0.0
| `-- source-map@0.5.7
+-- babel-loader@6.4.1
| +-- find-cache-dir@0.1.1
| | +-- commondir@1.0.1
| | `-- pkg-dir@1.0.0
| |   `-- find-up@1.1.2
| |     +-- path-exists@2.1.0
| |     `-- pinkie-promise@2.0.1
| |       `-- pinkie@2.0.4
| +-- loader-utils@0.2.17
| | +-- big.js@3.2.0
| | +-- emojis-list@2.1.0
| | `-- object-assign@4.1.1
| `-- object-assign@4.1.1
`-- UNMET DEPENDENCY webpack@^1.12.13

npm WARN babel-loader@6.4.1 requires a peer of webpack@1 || 2 || ^2.1.0-beta || ^2.2.0-rc but none was installed.

C:\Users\Bext\Desktop\react-todo-list_kweiberth>npm install --save-dev babel-preset-react
react-todo-list@1.0.0 C:\Users\Bext\Desktop\react-todo-list_kweiberth
+-- babel-preset-react@6.24.1
| +-- babel-plugin-syntax-jsx@6.18.0
| +-- babel-plugin-transform-react-display-name@6.25.0
| +-- babel-plugin-transform-react-jsx@6.24.1
| | `-- babel-helper-builder-react-jsx@6.26.0
| +-- babel-plugin-transform-react-jsx-self@6.22.0
| +-- babel-plugin-transform-react-jsx-source@6.22.0
| `-- babel-preset-flow@6.23.0
|   `-- babel-plugin-transform-flow-strip-types@6.22.0
|     `-- babel-plugin-syntax-flow@6.18.0
`-- UNMET DEPENDENCY webpack@^1.12.13

npm WARN babel-loader@6.4.1 requires a peer of webpack@1 || 2 || ^2.1.0-beta || ^2.2.0-rc but none was installed.

C:\Users\Bext\Desktop\react-todo-list_kweiberth>npm install --save-dev babel-preset-es2015
npm WARN deprecated babel-preset-es2015@6.24.1: �  Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update!
react-todo-list@1.0.0 C:\Users\Bext\Desktop\react-todo-list_kweiberth
+-- babel-preset-es2015@6.24.1
| +-- babel-plugin-check-es2015-constants@6.22.0
| +-- babel-plugin-transform-es2015-arrow-functions@6.22.0
| +-- babel-plugin-transform-es2015-block-scoped-functions@6.22.0
| +-- babel-plugin-transform-es2015-block-scoping@6.26.0
| +-- babel-plugin-transform-es2015-classes@6.24.1
| | +-- babel-helper-define-map@6.26.0
| | +-- babel-helper-function-name@6.24.1
| | +-- babel-helper-optimise-call-expression@6.24.1
| | `-- babel-helper-replace-supers@6.24.1
| +-- babel-plugin-transform-es2015-computed-properties@6.24.1
| +-- babel-plugin-transform-es2015-destructuring@6.23.0
| +-- babel-plugin-transform-es2015-duplicate-keys@6.24.1
| +-- babel-plugin-transform-es2015-for-of@6.23.0
| +-- babel-plugin-transform-es2015-function-name@6.24.1
| +-- babel-plugin-transform-es2015-literals@6.22.0
| +-- babel-plugin-transform-es2015-modules-amd@6.24.1
| +-- babel-plugin-transform-es2015-modules-commonjs@6.26.0
| | `-- babel-plugin-transform-strict-mode@6.24.1
| +-- babel-plugin-transform-es2015-modules-systemjs@6.24.1
| | `-- babel-helper-hoist-variables@6.24.1
| +-- babel-plugin-transform-es2015-modules-umd@6.24.1
| +-- babel-plugin-transform-es2015-object-super@6.24.1
| +-- babel-plugin-transform-es2015-parameters@6.24.1
| | +-- babel-helper-call-delegate@6.24.1
| | `-- babel-helper-get-function-arity@6.24.1
| +-- babel-plugin-transform-es2015-shorthand-properties@6.24.1
| +-- babel-plugin-transform-es2015-spread@6.22.0
| +-- babel-plugin-transform-es2015-sticky-regex@6.24.1
| | `-- babel-helper-regex@6.26.0
| +-- babel-plugin-transform-es2015-template-literals@6.22.0
| +-- babel-plugin-transform-es2015-typeof-symbol@6.23.0
| +-- babel-plugin-transform-es2015-unicode-regex@6.24.1
| | `-- regexpu-core@2.0.0
| |   +-- regenerate@1.3.3
| |   +-- regjsgen@0.2.0
| |   `-- regjsparser@0.1.5
| |     `-- jsesc@0.5.0
| `-- babel-plugin-transform-regenerator@6.26.0
|   `-- regenerator-transform@0.10.1
`-- UNMET DEPENDENCY webpack@^1.12.13

npm WARN babel-loader@6.4.1 requires a peer of webpack@1 || 2 || ^2.1.0-beta || ^2.2.0-rc but none was installed.

- Ahora si ejecutamos el comando de Webpack para generar bundle.js

C:\Users\Bext\Desktop\react-todo-list_kweiberth>webpack --config webpack.config.js
(node:5872) DeprecationWarning: loaderUtils.parseQuery() received a non-string value which can be problematic, see https://github.com/webpack/loader-utils/issues/56
parseQuery() will be replaced with getOptions() in the next major version of loader-utils.
Hash: 43a65204cf70d9653829
Version: webpack 3.8.1
Time: 6111ms
    Asset    Size  Chunks                    Chunk Names
bundle.js  674 kB       0  [emitted]  [big]  main
  [86] multi ./client/client.js 28 bytes {0} [built]
  [87] ./client/client.js 666 bytes {0} [built]
    + 159 hidden modules

- Tenemos como resultado en el Browser



miércoles, 29 de noviembre de 2017

JavaScript Patterns for 2017


Esta es una extraordinaria y útil platica acerca de mejores prácticas sobre el uso de javascript considerando los cambios de los últimos años con ecmascrip2015, ecmascript2016, ecmascript2017.
Como usar los modulos de js. como y porque hay pifias en algunos patrones comunmente aplicados por desarrolladores. Como organizar el código y el por que, pros y contras de las nuevas versiones.
  Scott Allen lo expresa de forma rápida y concisa.

youtube.com JavaScript Patterns for 2017 Scott Allen
https://www.youtube.com/watch?v=hO7mzO83N1Q

Toda esta actualización en una hora.

Spring Framework Swiss Knife Git



Esto es una herramienta y guía para Spring Framework

El árbol Git que se muestra en la figura contiene el código de los puntos que maneja el Framework de spring
El código en Git https://github.com/jalbertomr/HelloSpring.git

Haciendo el Checkout respectivo al commit  nos deja el contenido del proyecto con el Tema indicado en el nodo del árbol Git.





jueves, 16 de noviembre de 2017

MongoDB plugin para IntelliJ

Agregemos un plugin de MongoDB para integrar su vista el editor IDE de IntelliJ

Es muy sencillo, basicamente se agrega como agregariamos cualquier otro plugin, en Menu de IntelliJ IDE  File->setting->Browse Repositories


y Ya podemos la vista Mongo Explorer, vemos nuestra conexión localhost y Cloud, y los datos de la collection clientes que poblamos en un Post anterior. las conexiones las configuramos partiendo de los datos que nos da MongoDB.


y esta es la gracia de la integración.

MongoDB Atlas la versión Cloud

Esta es nuestra vista de nuestro MongoDB en la Nube


Para esto seguimos las amables instrucciones que nos da la página de MongoDB para dar de alta nuestro Cluster. Tenemos que bajar el Shell de MongoDB para Cloud. ya hemos dado de alta las direcciones IP de los clientes que utilizarán MongoDB Atlas Cloud.


En el botton Connect no da las instrucciones para conectar desde el Shell o Aplicación o MongoDB Compress.

Conectemonos con el Shell command line


Corremos el comando que nos proporciona el Cluster de Atlas en una ventana de commandos, y hacemos algunos sencillos comandos de prueba de verificación de datos.


Ahora conectemonos con MongoDB Compass Community


y tenemos algo similar al caso de cuando nos conectamos con el servidor local de MongoDB.


MongoDB Compass Community

MongoDB tiene una serie de herramientas para facilitar la vida en el trabajo de manejo de sus datos
una de ellas en MongoDB Compass Community, misma que se descarga del sitio de MongoDB


Esta es la primera parte para conectarnos a nuestro MongoDB local, localhost puerto 27017, se puede observar otras conecciones recientes, esas corresponden a MondoDB Atlas que es su versión Cloud, pero eso lo dejamos para el siguiente post.


una ves conectados, tengremos dos Databases por default admin y local, BetoDB es la que creamos y poblamos en el Post anterior.


Vemos la collection que creamos clientes.


y los datos que poblamos en la práctica del Post Anterior.

MongoDB Server Instalación y Command Line Practice

La instalación de MongoDB no es complicada, solo hay que leer un poquito la documentación que ofrece su sitio, la cual es sencilla, amena y fácil. https://www.mongodb.com/es
   Hay una variedad de instalaciones y modalidades, por el momento para no perdernos solo instalaremos el SERVER para correr en la máquina local, Tambien se ofrece la version CLOUD con MongoDB Atlas.


Bajaremos la version windows, es un archivo msi, y en la instalación nos permite agregar características adicionales.

la instalación por default es en C:\Program Files\MongoDB\Server\3.4 y permite configurar donde guardaremos los datos, que en mi caso sera en F:\Mongo\data\db y F:\Mongo\log creamos estos subdirectorios ya que al arrancar el servidor de mongo le indicaremos estos paths.

para facilitar el acceso a los comandos de MongoDB agregaremos al Path del sistema la ruta C:\Program Files\MongoDB\Server\3.4\bin

damos el comando para arrancar el servidor desde una ventana de linea de comandos iniciada en modo administrador.
>mongod --directoryperdb --dbpath F:\Mongo\data\db --logpath F:\Mongo\log\mongo.log --logappend --rest --install
2017-11-16T10:54:48.395-0600 I CONTROL  [main] ** WARNING: --rest is specified without --httpinterface,
2017-11-16T10:54:48.397-0600 I CONTROL  [main] **          enabling http interface

En el comando dimos la opcion --install que lo ejecuta como servicio, así que si no es la primera vez que se ejecuta ya estara como servicio de windows, para ello vamos a servicios de windows y nos cercioramos que este en ejecucion MongoDB.

Revisamos en un browser la dirección http://localhost:27017/
It looks like you are trying to access MongoDB over HTTP on the native driver port.

 ahora ejecutaremos el shell de mongo para poder dar comandos.
>mongo
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
Server has startup warnings:
2017-11-16T10:57:21.029-0600 I CONTROL  [main] ** WARNING: --rest is specified without --httpinterface,
2017-11-16T10:57:21.030-0600 I CONTROL  [main] **          enabling http interface
2017-11-16T10:57:24.374-0600 I CONTROL  [initandlisten]
2017-11-16T10:57:24.374-0600 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-11-16T10:57:24.374-0600 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-11-16T10:57:24.374-0600 I CONTROL  [initandlisten]

> db
test
> show dbs
admin  0.000GB
local  0.000GB
> use BetoDB
switched to db BetoDB
> db
BetoDB
 > db.createUser({user:"Beto",pwd:"Beto",roles:["readWrite","dbAdmin"]});
Successfully added user: { "user" : "Beto", "roles" : [ "readWrite", "dbAdmin" ] }
> db.createCollection('clientes');
{ "ok" : 1 }
> db.clientes.insert({nombre:"Juan", apellido:"Perez"});
WriteResult({ "nInserted" : 1 })
> db.clientes.find();
{ "_id" : ObjectId("5a0d0918f211ce4f67261bcb"), "nombre" : "Juan", "apellido" : "Perez" }
> show collections
clientes

> db.clientes.insert({nombre:"Rod", apellido:"Campos"});
WriteResult({ "nInserted" : 1 })
> db.clientes.find();
{ "_id" : ObjectId("5a0d0918f211ce4f67261bcb"), "nombre" : "Juan", "apellido" : "Perez" }
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "nombre" : "Rod", "apellido" : "Campos" }
>  db.clientes.insert({nombre:"Juan", apellido:"Perez"},{nombre:"Denisse", apellido:"Swarts", genero:"femenino"});
WriteResult({ "nInserted" : 1 })
> db.clientes.find();
{ "_id" : ObjectId("5a0d0918f211ce4f67261bcb"), "nombre" : "Juan", "apellido" : "Perez" }
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "nombre" : "Rod", "apellido" : "Campos" }
{ "_id" : ObjectId("5a0dc93a6dd8b456f1b39f62"), "nombre" : "Juan", "apellido" : "Perez" }
> db.clientes.insert([{nombre:"Juan", apellido:"Perez"},{nombre:"Denisse", apellido:"Swarts", genero:"femenino"}]);
BulkWriteResult({
        "writeErrors" : [ ],
        "writeConcernErrors" : [ ],
        "nInserted" : 2,
        "nUpserted" : 0,
        "nMatched" : 0,
        "nModified" : 0,
        "nRemoved" : 0,
        "upserted" : [ ]
})
> db.clientes.find().pretty()
{
        "_id" : ObjectId("5a0d0918f211ce4f67261bcb"),
        "nombre" : "Juan",
        "apellido" : "Perez"
}
{
        "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"),
        "nombre" : "Rod",
        "apellido" : "Campos"
}
{
        "_id" : ObjectId("5a0dc93a6dd8b456f1b39f62"),
        "nombre" : "Juan",
        "apellido" : "Perez"
}
{
        "_id" : ObjectId("5a0dc9a86dd8b456f1b39f63"),
        "nombre" : "Juan",
        "apellido" : "Perez"
}
{
        "_id" : ObjectId("5a0dc9a86dd8b456f1b39f64"),
        "nombre" : "Denisse",
        "apellido" : "Swarts",
        "genero" : "femenino"
}
> db.clientes.remove({_id: ObjectId("5a0dc9a86dd8b456f1b39f64")});
WriteResult({ "nRemoved" : 1 })
> db.clientes.find().pretty();
{
        "_id" : ObjectId("5a0d0918f211ce4f67261bcb"),
        "nombre" : "Juan",
        "apellido" : "Perez"
}
{
        "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"),
        "nombre" : "Rod",
        "apellido" : "Campos"
}
{
        "_id" : ObjectId("5a0dc93a6dd8b456f1b39f62"),
        "nombre" : "Juan",
        "apellido" : "Perez"
}
{
        "_id" : ObjectId("5a0dc9a86dd8b456f1b39f63"),
        "nombre" : "Juan",
        "apellido" : "Perez"
}
> db.clientes.remove({nombre:"Juan"});
WriteResult({ "nRemoved" : 3 })
> db.clientes.insert({nombre:"Juan", apellido:"Perez"});
WriteResult({ "nInserted" : 1 })
> db.clientes.insert({nombre:"Juan", apellido:"Lopez"});
WriteResult({ "nInserted" : 1 })
> db.clientes.find();
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "nombre" : "Rod", "apellido" : "Campos" }
{ "_id" : ObjectId("5a0dcbdc6dd8b456f1b39f65"), "nombre" : "Juan", "apellido" : "Perez" }
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez" }
> db.clientes.update({nombre:"Juan"},{nombre:"Juan", apellido:"Perez", genero:"masculino"});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.clientes.find();
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "nombre" : "Rod", "apellido" : "Campos" }
{ "_id" : ObjectId("5a0dcbdc6dd8b456f1b39f65"), "nombre" : "Juan", "apellido" : "Perez", "genero" : "masculino" }
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez" }

> db.clientes.update({nombre:"Juan"},{$set:{genero:"femenino"}});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.clientes.find();
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "nombre" : "Rod", "apellido" : "Campos" }
{ "_id" : ObjectId("5a0dcbdc6dd8b456f1b39f65"), "nombre" : "Juan", "apellido" : "Perez", "genero" : "femenino" }
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez" }
> db.clientes.update({nombre:"Juan"},{$set:{edad:21}});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.clientes.find();
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "nombre" : "Rod", "apellido" : "Campos" }
{ "_id" : ObjectId("5a0dcbdc6dd8b456f1b39f65"), "nombre" : "Juan", "apellido" : "Perez", "genero" : "femenino", "edad" : 21 }
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez" }

> db.clientes.update({nombre:"Juan"},{$inc:{edad:3}});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.clientes.find();
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "nombre" : "Rod", "apellido" : "Campos" }
{ "_id" : ObjectId("5a0dcbdc6dd8b456f1b39f65"), "nombre" : "Juan", "apellido" : "Perez", "genero" : "femenino", "edad" : 24 }
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez" }

> db.clientes.update({nombre:"Juan"},{$unset:{edad:1}});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.clientes.find();
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "nombre" : "Rod", "apellido" : "Campos" }
{ "_id" : ObjectId("5a0dcbdc6dd8b456f1b39f65"), "nombre" : "Juan", "apellido" : "Perez", "genero" : "femenino" }
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez" }

> db.clientes.update({nombre:"Maria"},{nombre:"Maria", apellido:"Morales"});
WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
> db.clientes.update({nombre:"Maria"},{nombre:"Maria", apellido:"Morales"},{upsert:true});
WriteResult({
        "nMatched" : 0,
        "nUpserted" : 1,
        "nModified" : 0,
        "_id" : ObjectId("5a0dceb19705684e76048b3f")
})
> db.clientes.find();
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "nombre" : "Rod", "apellido" : "Campos" }
{ "_id" : ObjectId("5a0dcbdc6dd8b456f1b39f65"), "nombre" : "Juan", "apellido" : "Perez", "genero" : "femenino" }
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez" }
{ "_id" : ObjectId("5a0dceb19705684e76048b3f"), "nombre" : "Maria", "apellido" : "Morales" }

> db.clientes.update({nombre:"Juan"},{$rename:{"genero":"sexo"}});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.clientes.find();
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "nombre" : "Rod", "apellido" : "Campos" }
{ "_id" : ObjectId("5a0dcbdc6dd8b456f1b39f65"), "nombre" : "Juan", "apellido" : "Perez", "sexo" : "femenino" }
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez" }
{ "_id" : ObjectId("5a0dceb19705684e76048b3f"), "nombre" : "Maria", "apellido" : "Morales" }

> db.clientes.remove({nombre:"Juan"},{justOne:true});
WriteResult({ "nRemoved" : 1 })
> db.clientes.find();
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "nombre" : "Rod", "apellido" : "Campos" }
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez" }
{ "_id" : ObjectId("5a0dceb19705684e76048b3f"), "nombre" : "Maria", "apellido" : "Morales" }se meten mas elementos

>db.clientes.insert([
... {
... nombres:"Ricardo",
... apellidos:"Rodriguez",
... edad:35,
... membresias: ["normal","platino"],
... direccion:{
... calle:"Yacatas 12",
... ciudad:"Mexico",
... estado:"Mexico"
... },
... contactos:[
... {nombre:"Mauricio", relacion:"hermano"},
... {nombre:"Tere", relacion:"tia"}
... ],
... balance:999.23
... },
... {
... nombres:"Adriana",
... apellidos:"Cuervo",
... edad:27,
... membresias: "plus",
... direccion:{
... calle:"rododendro 43",
... ciudad:"Jalapa",
... estado:"Veracruz"
... },
... contactos:[
... {nombre:"Marco", relacion:"hijo"},
... {nombre:"Carlo", relacion:"hijo"}
... ],
... balance:743.21
... },
... {
... nombres:"Susana",
... apellidos:"Prado",
... edad:18,
... membresias: "simple",
... direccion:{
... calle:"Amargura 98",
... ciudad:"Merida",
... estado:"Yucatan"
... },
... contactos:{nombre:"Jessica", relacion:"hija"},
... balance:34.44
... },
... {
... nombres:"Papa",
... apellidos:"Gorgorio",
... edad:76,
... membresias: ["santa","platino"],
... direccion:{
... calle:"Iglecia 4",
... ciudad:"Roma",
... estado:"Vaticano"
... },
... contactos:[
... {nombre:"Lady Gaga", relacion:"amiga"},
... {nombre:"Jorge Bush", relacion:"enemigo"}
... ],
... balance:2434589.23
... }]);
BulkWriteResult({
        "writeErrors" : [ ],
        "writeConcernErrors" : [ ],
        "nInserted" : 4,
        "nUpserted" : 0,
        "nMatched" : 0,
        "nModified" : 0,
        "nRemoved" : 0,
        "upserted" : [ ]
})
> db.clientes.find();
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "nombre" : "Rod", "apellido" : "Campos" }
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez" }
{ "_id" : ObjectId("5a0dceb19705684e76048b3f"), "nombre" : "Maria", "apellido" : "Morales" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f67"), "nombres" : "Ricardo", "apellidos" : "Rodriguez", "edad" : 35, "membresias" : [ "normal", "platino" ], "direccion" : { "calle" : "Yacatas 12", "ciudad" : "Mexico", "estado" : "Mexico" }, "contactos" : [ { "nombre" : "Mauricio", "relacion" : "hermano" }, { "nombre" : "Tere", "relacion" : "tia" } ], "balance" : 999.23 }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f68"), "nombres" : "Adriana", "apellidos" : "Cuervo", "edad" : 27, "membresias" : "plus", "direccion" : { "calle" : "rododendro 43", "ciudad" : "Jalapa", "estado" : "Veracruz" }, "contactos" : [ { "nombre" : "Marco", "relacion" : "hijo" }, { "nombre" : "Carlo", "relacion" : "hijo" } ], "balance" : 743.21 }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f69"), "nombres" : "Susana", "apellidos" : "Prado", "edad" : 18, "membresias" : "simple", "direccion" : { "calle" : "Amargura 98", "ciudad" : "Merida", "estado" : "Yucatan" }, "contactos" : { "nombre" : "Jessica", "relacion" : "hija" }, "balance" : 34.44 }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f6a"), "nombres" : "Papa", "apellidos" : "Gorgorio", "edad" : 76, "membresias" : [ "santa", "platino" ], "direccion" : { "calle" : "Iglecia 4", "ciudad" : "Roma", "estado" : "Vaticano" }, "contactos" : [ { "nombre" : "Lady Gaga", "relacion" : "amiga" }, { "nombre" : "Jorge Bush", "relacion" : "enemigo" } ], "balance" : 2434589.23 }

> db.clientes.update({nombres:"Adriana"},{$rename:{"nombres":"nombre"}});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.clientes.update({nombres:"Ricardo"},{$rename:{"nombres":"nombre"}});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.clientes.update({nombres:"Susana"},{$rename:{"nombres":"nombre"}});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.clientes.update({nombres:"Papa"},{$rename:{"nombres":"nombre"}});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

> db.clientes.find()
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "nombre" : "Rod", "apellido" : "Campos" }
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez" }
{ "_id" : ObjectId("5a0dceb19705684e76048b3f"), "nombre" : "Maria", "apellido" : "Morales" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f67"), "apellidos" : "Rodriguez", "edad" : 35, "membresias" : [ "normal", "platino" ], "direccion" : { "calle" : "Yacatas 12", "ciudad" : "Mexico", "estado" : "Mexico" }, "contactos" : [ { "nombre" : "Mauricio", "relacion" : "hermano" }, { "nombre" : "Tere", "relacion" : "tia" } ], "balance" : 999.23, "nombre" : "Ricardo" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f68"), "apellidos" : "Cuervo", "edad" : 27, "membresias" : "plus", "direccion" : { "calle" : "rododendro 43", "ciudad" : "Jalapa", "estado" : "Veracruz" }, "contactos" : [ { "nombre" : "Marco", "relacion" : "hijo" }, { "nombre" : "Carlo", "relacion" : "hijo" } ], "balance" : 743.21, "nombre" : "Adriana" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f69"), "apellidos" : "Prado", "edad" : 18, "membresias" : "simple", "direccion" : { "calle" : "Amargura 98", "ciudad" : "Merida", "estado" : "Yucatan" }, "contactos" : { "nombre" : "Jessica", "relacion" : "hija" }, "balance" : 34.44, "nombre" : "Susana" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f6a"), "apellidos" : "Gorgorio", "edad" : 76, "membresias" : [ "santa", "platino" ], "direccion" : { "calle" : "Iglecia 4", "ciudad" : "Roma", "estado" : "Vaticano" }, "contactos" : [ { "nombre" : "Lady Gaga", "relacion" : "amiga" }, { "nombre" : "Jorge Bush", "relacion" : "enemigo" } ], "balance" : 2434589.23, "nombre" : "Papa" }

> db.clientes.find({nombre:"Adriana"});
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f68"), "apellidos" : "Cuervo", "edad" : 27, "membresias" : "plus", "direccion" : { "calle" : "rododendro 43", "ciudad" : "Jalapa", "estado" : "Veracruz" }, "contactos" : [ { "nombre" : "Marco", "relacion" : "hijo" }, { "nombre" : "Carlo", "relacion" : "hijo" } ], "balance" : 743.21, "nombre" : "Adriana" }

> db.clientes.find({$or:[{nombre:"Adriana"},{nombre:"Ricardo"}]})
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f67"), "apellidos" : "Rodriguez", "edad" : 35, "membresias" : [ "normal", "platino" ], "direccion" : { "calle" : "Yacatas 12", "ciudad" : "Mexico", "estado" : "Mexico" }, "contactos" : [ { "nombre" : "Mauricio", "relacion" : "hermano" }, { "nombre" : "Tere", "relacion" : "tia" } ], "balance" : 999.23, "nombre" : "Ricardo" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f68"), "apellidos" : "Cuervo", "edad" : 27, "membresias" : "plus", "direccion" : { "calle" : "rododendro 43", "ciudad" : "Jalapa", "estado" : "Veracruz" }, "contactos" : [ { "nombre" : "Marco", "relacion" : "hijo" }, { "nombre" : "Carlo", "relacion" : "hijo" } ], "balance" : 743.21, "nombre" : "Adriana" }

> db.clientes.find().pretty();
{
        "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"),
        "nombre" : "Rod",
        "apellido" : "Campos"
}
{
        "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"),
        "nombre" : "Juan",
        "apellido" : "Lopez"
}
{
        "_id" : ObjectId("5a0dceb19705684e76048b3f"),
        "nombre" : "Maria",
        "apellido" : "Morales"
}
{
        "_id" : ObjectId("5a0dd0726dd8b456f1b39f67"),
        "apellidos" : "Rodriguez",
        "edad" : 35,
        "membresias" : [
                "normal",
                "platino"
        ],
        "direccion" : {
                "calle" : "Yacatas 12",
                "ciudad" : "Mexico",
                "estado" : "Mexico"
        },
        "contactos" : [
                {
                        "nombre" : "Mauricio",
                        "relacion" : "hermano"
                },
                {
                        "nombre" : "Tere",
                        "relacion" : "tia"
                }
        ],
        "balance" : 999.23,
        "nombre" : "Ricardo"
}
{
        "_id" : ObjectId("5a0dd0726dd8b456f1b39f68"),
        "apellidos" : "Cuervo",
        "edad" : 27,
        "membresias" : "plus",
        "direccion" : {
                "calle" : "rododendro 43",
                "ciudad" : "Jalapa",
                "estado" : "Veracruz"
        },
        "contactos" : [
                {
                        "nombre" : "Marco",
                        "relacion" : "hijo"
                },
                {
                        "nombre" : "Carlo",
                        "relacion" : "hijo"
                }
        ],
        "balance" : 743.21,
        "nombre" : "Adriana"
}
{
        "_id" : ObjectId("5a0dd0726dd8b456f1b39f69"),
        "apellidos" : "Prado",
        "edad" : 18,
        "membresias" : "simple",
        "direccion" : {
                "calle" : "Amargura 98",
                "ciudad" : "Merida",
                "estado" : "Yucatan"
        },
        "contactos" : {
                "nombre" : "Jessica",
                "relacion" : "hija"
        },
        "balance" : 34.44,
        "nombre" : "Susana"
}
{
        "_id" : ObjectId("5a0dd0726dd8b456f1b39f6a"),
        "apellidos" : "Gorgorio",
        "edad" : 76,
        "membresias" : [
                "santa",
                "platino"
        ],
        "direccion" : {
                "calle" : "Iglecia 4",
                "ciudad" : "Roma",
                "estado" : "Vaticano"
        },
        "contactos" : [
                {
                        "nombre" : "Lady Gaga",
                        "relacion" : "amiga"
                },
                {
                        "nombre" : "Jorge Bush",
                        "relacion" : "enemigo"
                }
        ],
        "balance" : 2434589.23,
        "nombre" : "Papa"
}

> db.clientes.find({edad:18});
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f69"), "apellidos" : "Prado", "edad" : 18, "membresias" : "simple", "direccion" : { "calle" : "Amargura 98", "ciudad" : "Merida", "estado" : "Yucatan" }, "contactos" : { "nombre" : "Jessica", "relacion" : "hija" }, "balance" : 34.44, "nombre" : "Susana" }
> db.clientes.find({edad:{$lt:30}}).pretty();
{
        "_id" : ObjectId("5a0dd0726dd8b456f1b39f68"),
        "apellidos" : "Cuervo",
        "edad" : 27,
        "membresias" : "plus",
        "direccion" : {
                "calle" : "rododendro 43",
                "ciudad" : "Jalapa",
                "estado" : "Veracruz"
        },
        "contactos" : [
                {
                        "nombre" : "Marco",
                        "relacion" : "hijo"
                },
                {
                        "nombre" : "Carlo",
                        "relacion" : "hijo"
                }
        ],
        "balance" : 743.21,
        "nombre" : "Adriana"
}
{
        "_id" : ObjectId("5a0dd0726dd8b456f1b39f69"),
        "apellidos" : "Prado",
        "edad" : 18,
        "membresias" : "simple",
        "direccion" : {
                "calle" : "Amargura 98",
                "ciudad" : "Merida",
                "estado" : "Yucatan"
        },
        "contactos" : {
                "nombre" : "Jessica",
                "relacion" : "hija"
        },
        "balance" : 34.44,
        "nombre" : "Susana"
}

> db.clientes.find({edad:{$gt:30}}).pretty();
{
        "_id" : ObjectId("5a0dd0726dd8b456f1b39f67"),
        "apellidos" : "Rodriguez",
        "edad" : 35,
        "membresias" : [
                "normal",
                "platino"
        ],
        "direccion" : {
                "calle" : "Yacatas 12",
                "ciudad" : "Mexico",
                "estado" : "Mexico"
        },
        "contactos" : [
                {
                        "nombre" : "Mauricio",
                        "relacion" : "hermano"
                },
                {
                        "nombre" : "Tere",
                        "relacion" : "tia"
                }
        ],
        "balance" : 999.23,
        "nombre" : "Ricardo"
}
{
        "_id" : ObjectId("5a0dd0726dd8b456f1b39f6a"),
        "apellidos" : "Gorgorio",
        "edad" : 76,
        "membresias" : [
                "santa",
                "platino"
        ],
        "direccion" : {
                "calle" : "Iglecia 4",
                "ciudad" : "Roma",
                "estado" : "Vaticano"
        },
        "contactos" : [
                {
                        "nombre" : "Lady Gaga",
                        "relacion" : "amiga"
                },
                {
                        "nombre" : "Jorge Bush",
                        "relacion" : "enemigo"
                }
        ],
        "balance" : 2434589.23,
        "nombre" : "Papa"
}

> db.clientes.find({edad:{$eq:18}});
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f69"), "apellidos" : "Prado", "edad" : 18, "membresias" : "simple", "direccion" : { "calle" : "Amargura 98", "ciudad" : "Merida", "estado" : "Yucatan" }, "contactos" : { "nombre" : "Jessica", "relacion" : "hija" }, "balance" : 34.44, "nombre" : "Susana" }

> db.clientes.find({"direccion.ciudad":"Merida"});
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f69"), "apellidos" : "Prado", "edad" : 18, "membresias" : "simple", "direccion" : { "calle" : "Amargura 98", "ciudad" : "Merida", "estado" : "Yucatan" }, "contactos" : { "nombre" : "Jessica", "relacion" : "hija" }, "balance" : 34.44, "nombre" : "Susana" }
> db.clientes.find({"direccion.ciudad":"Mexico"});
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f67"), "apellidos" : "Rodriguez", "edad" : 35, "membresias" : [ "normal", "platino" ], "direccion" : { "calle" : "Yacatas 12", "ciudad" : "Mexico", "estado" : "Mexico" }, "contactos" : [ { "nombre" : "Mauricio", "relacion" : "hermano" }, { "nombre" : "Tere", "relacion" : "tia" } ], "balance" : 999.23, "nombre" : "Ricardo" }

> db.clientes.find({membresias:"plus"});
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f68"), "apellidos" : "Cuervo", "edad" : 27, "membresias" : "plus", "direccion" : { "calle" : "rododendro 43", "ciudad" : "Jalapa", "estado" : "Veracruz" }, "contactos" : [ { "nombre" : "Marco", "relacion" : "hijo" }, { "nombre" : "Carlo", "relacion" : "hijo" } ], "balance" : 743.21, "nombre" : "Adriana" }

> db.clientes.find().sort({apellidos:1});  // ascendente
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "nombre" : "Rod", "apellido" : "Campos" }
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez" }
{ "_id" : ObjectId("5a0dceb19705684e76048b3f"), "nombre" : "Maria", "apellido" : "Morales" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f68"), "apellidos" : "Cuervo", "edad" : 27, "membresias" : "plus", "direccion" : { "calle" : "rododendro 43", "ciudad" : "Jalapa", "estado" : "Veracruz" }, "contactos" : [ { "nombre" : "Marco", "relacion" : "hijo" }, { "nombre" : "Carlo", "relacion" : "hijo" } ], "balance" : 743.21, "nombre" : "Adriana" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f6a"), "apellidos" : "Gorgorio", "edad" : 76, "membresias" : [ "santa", "platino" ], "direccion" : { "calle" : "Iglecia 4", "ciudad" : "Roma", "estado" : "Vaticano" }, "contactos" : [ { "nombre" : "Lady Gaga", "relacion" : "amiga" }, { "nombre" : "Jorge Bush", "relacion" : "enemigo" } ], "balance" : 2434589.23, "nombre" : "Papa" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f69"), "apellidos" : "Prado", "edad" : 18, "membresias" : "simple", "direccion" : { "calle" : "Amargura 98", "ciudad" : "Merida", "estado" : "Yucatan" }, "contactos" : { "nombre" : "Jessica", "relacion" : "hija" }, "balance" : 34.44, "nombre" : "Susana" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f67"), "apellidos" : "Rodriguez", "edad" : 35, "membresias" : [ "normal", "platino" ], "direccion" : { "calle" : "Yacatas 12", "ciudad" : "Mexico", "estado" : "Mexico" }, "contactos" : [ { "nombre" : "Mauricio", "relacion" : "hermano" }, { "nombre" : "Tere", "relacion" : "tia" } ], "balance" : 999.23, "nombre" : "Ricardo" }

> db.clientes.find().sort({apellidos:-1});  // descendente
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f67"), "apellidos" : "Rodriguez", "edad" : 35, "membresias" : [ "normal", "platino" ], "direccion" : { "calle" : "Yacatas 12", "ciudad" : "Mexico", "estado" : "Mexico" }, "contactos" : [ { "nombre" : "Mauricio", "relacion" : "hermano" }, { "nombre" : "Tere", "relacion" : "tia" } ], "balance" : 999.23, "nombre" : "Ricardo" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f69"), "apellidos" : "Prado", "edad" : 18, "membresias" : "simple", "direccion" : { "calle" : "Amargura 98", "ciudad" : "Merida", "estado" : "Yucatan" }, "contactos" : { "nombre" : "Jessica", "relacion" : "hija" }, "balance" : 34.44, "nombre" : "Susana" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f6a"), "apellidos" : "Gorgorio", "edad" : 76, "membresias" : [ "santa", "platino" ], "direccion" : { "calle" : "Iglecia 4", "ciudad" : "Roma", "estado" : "Vaticano" }, "contactos" : [ { "nombre" : "Lady Gaga", "relacion" : "amiga" }, { "nombre" : "Jorge Bush", "relacion" : "enemigo" } ], "balance" : 2434589.23, "nombre" : "Papa" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f68"), "apellidos" : "Cuervo", "edad" : 27, "membresias" : "plus", "direccion" : { "calle" : "rododendro 43", "ciudad" : "Jalapa", "estado" : "Veracruz" }, "contactos" : [ { "nombre" : "Marco", "relacion" : "hijo" }, { "nombre" : "Carlo", "relacion" : "hijo" } ], "balance" : 743.21, "nombre" : "Adriana" }
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "nombre" : "Rod", "apellido" : "Campos" }
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez" }
{ "_id" : ObjectId("5a0dceb19705684e76048b3f"), "nombre" : "Maria", "apellido" : "Morales" }


> db.clientes.update({},{$rename:{"apellidos":"apellido"}}, {upsert:false, multi:true});
WriteResult({ "nMatched" : 7, "nUpserted" : 0, "nModified" : 4 })

> db.clientes.find().sort({apellido:-1});
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f67"), "edad" : 35, "membresias" : [ "normal", "platino" ], "direccion" : { "calle" : "Yacatas 12", "ciudad" : "Mexico", "estado" : "Mexico" }, "contactos" : [ { "nombre" : "Mauricio", "relacion" : "hermano" }, { "nombre" : "Tere", "relacion" : "tia" } ], "balance" : 999.23, "nombre" : "Ricardo", "apellido" : "Rodriguez" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f69"), "edad" : 18, "membresias" : "simple", "direccion" : { "calle" : "Amargura 98", "ciudad" : "Merida", "estado" : "Yucatan" }, "contactos" : { "nombre" : "Jessica", "relacion" : "hija" }, "balance" : 34.44, "nombre" : "Susana", "apellido" : "Prado" }
{ "_id" : ObjectId("5a0dceb19705684e76048b3f"), "nombre" : "Maria", "apellido" : "Morales" }
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f6a"), "edad" : 76, "membresias" : [ "santa", "platino" ], "direccion" : { "calle" : "Iglecia 4", "ciudad" : "Roma", "estado" : "Vaticano" }, "contactos" : [ { "nombre" : "Lady Gaga", "relacion" : "amiga" }, { "nombre" : "Jorge Bush", "relacion" : "enemigo" } ], "balance" : 2434589.23, "nombre" : "Papa", "apellido" : "Gorgorio" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f68"), "edad" : 27, "membresias" : "plus", "direccion" : { "calle" : "rododendro 43", "ciudad" : "Jalapa", "estado" : "Veracruz" }, "contactos" : [ { "nombre" : "Marco", "relacion" : "hijo" }, { "nombre" : "Carlo", "relacion" : "hijo" } ], "balance" : 743.21, "nombre" : "Adriana", "apellido" : "Cuervo" }
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "nombre" : "Rod", "apellido" : "Campos" }

> db.clientes.find({ },{apellido:1}).sort({apellido:-1});
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f67"), "apellido" : "Rodriguez" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f69"), "apellido" : "Prado" }
{ "_id" : ObjectId("5a0dceb19705684e76048b3f"), "apellido" : "Morales" }
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "apellido" : "Lopez" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f6a"), "apellido" : "Gorgorio" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f68"), "apellido" : "Cuervo" }
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "apellido" : "Campos" }

> db.clientes.find({ },{apellido:1}).sort({apellido:1});
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "apellido" : "Campos" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f68"), "apellido" : "Cuervo" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f6a"), "apellido" : "Gorgorio" }
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "apellido" : "Lopez" }
{ "_id" : ObjectId("5a0dceb19705684e76048b3f"), "apellido" : "Morales" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f69"), "apellido" : "Prado" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f67"), "apellido" : "Rodriguez" }

> db.clientes.find({ },{apellido:1,nombre:1,edad:1}).sort({apellido:1});
{ "_id" : ObjectId("5a0dc8e56dd8b456f1b39f61"), "nombre" : "Rod", "apellido" : "Campos" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f68"), "edad" : 27, "nombre" : "Adriana", "apellido" : "Cuervo" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f6a"), "edad" : 76, "nombre" : "Papa", "apellido" : "Gorgorio" }
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez" }
{ "_id" : ObjectId("5a0dceb19705684e76048b3f"), "nombre" : "Maria", "apellido" : "Morales" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f69"), "edad" : 18, "nombre" : "Susana", "apellido" : "Prado" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f67"), "edad" : 35, "nombre" : "Ricardo", "apellido" : "Rodriguez" }

> db.clientes.find().count();
7

> db.clientes.find({edad:{$gt:30}}).count();
2
> db.clientes.find({edad:{$lt:30}}).count();
2
>
> db.clientes.update({},{$set:{sexo:"Masculino"}},{upsert:true,multi:true});
WriteResult({ "nMatched" : 6, "nUpserted" : 0, "nModified" : 6 })
> db.clientes.find();
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez", "sexo" : "Masculino" }
{ "_id" : ObjectId("5a0dceb19705684e76048b3f"), "nombre" : "Maria", "apellido" : "Morales", "sexo" : "Masculino" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f67"), "edad" : 35, "membresias" : [ "normal", "platino" ], "direccion" : { "calle" : "Yacatas 12", "ciudad" : "Mexico", "estado" : "Mexico" }, "contactos" : [ { "nombre" : "Mauricio", "relacion" : "hermano" }, { "nombre" : "Tere", "relacion" : "tia" } ], "balance" : 999.23, "nombre" : "Ricardo", "apellido" : "Rodriguez", "sexo" : "Masculino" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f68"), "edad" : 27, "membresias" : "plus", "direccion" : { "calle" : "rododendro 43", "ciudad" : "Jalapa", "estado" : "Veracruz" }, "contactos" : [ { "nombre" : "Marco", "relacion" : "hijo" }, { "nombre" : "Carlo", "relacion" : "hijo" } ], "balance" : 743.21, "nombre" : "Adriana", "apellido" : "Cuervo", "sexo" : "Masculino" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f69"), "edad" : 18, "membresias" : "simple", "direccion" : { "calle" : "Amargura 98", "ciudad" : "Merida", "estado" : "Yucatan" }, "contactos" : { "nombre" : "Jessica", "relacion" : "hija" }, "balance" : 34.44, "nombre" : "Susana", "apellido" : "Prado", "sexo" : "Masculino" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f6a"), "edad" : 76, "membresias" : [ "santa", "platino" ], "direccion" : { "calle" : "Iglecia 4", "ciudad" : "Roma", "estado" : "Vaticano" }, "contactos" : [ { "nombre" : "Lady Gaga", "relacion" : "amiga" }, { "nombre" : "Jorge Bush", "relacion" : "enemigo" } ], "balance" : 2434589.23, "nombre" : "Papa", "apellido" : "Gorgorio", "sexo" : "Masculino" }

> db.clientes.find({"edad" : { $exists: false}});
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez", "sexo" : "Masculino" }
{ "_id" : ObjectId("5a0dceb19705684e76048b3f"), "nombre" : "Maria", "apellido" : "Morales", "sexo" : "Masculino" }


>db.clientes.update({}, {$set{borra:10}},{true,true});
>db.clientes.update({"edad" : { $exists: false}},{ $set{edad:15}},{upsert:true,multi:true});
>db.clientes.find({genero:"masculino"}).count();

> db.clientes.find().limit(3);
{ "_id" : ObjectId("5a0dcc296dd8b456f1b39f66"), "nombre" : "Juan", "apellido" : "Lopez", "sexo" : "Masculino" }
{ "_id" : ObjectId("5a0dceb19705684e76048b3f"), "nombre" : "Maria", "apellido" : "Morales", "sexo" : "Masculino" }
{ "_id" : ObjectId("5a0dd0726dd8b456f1b39f67"), "edad" : 35, "membresias" : [ "normal", "platino" ], "direccion" : { "calle" : "Yacatas 12", "ciudad" : "Mexico", "estado" : "Mexico" }, "contactos" : [ { "nombre" : "Mauricio", "relacion" : "hermano" }, { "nombre" : "Tere", "relacion" : "tia" } ], "balance" : 999.23, "nombre" : "Ricardo", "apellido" : "Rodriguez", "sexo" : "Masculino" }>db.clientes.find().limit(4).sort({apellido:1});

> db.clientes.find().forEach(function(doc){print("cliente : " + doc.nombre + " " + doc.apellido)});
cliente : Juan Lopez
cliente : Maria Morales
cliente : Ricardo Rodriguez
cliente : Adriana Cuervo
cliente : Susana Prado
cliente : Papa Gorgorio

> db.clientes.update({"edad" : { $exists: false}},{$set:{edad:15}},{multi:true});
WriteResult({ "nMatched" : 2, "nUpserted" : 0, "nModified" : 2 })

> db.clientes.find().forEach(function(doc){print("cliente : " + doc.apellido + " " + doc.nombre + " edad: " + doc.edad)});
cliente : Lopez Juan edad: 15
cliente : Morales Maria edad: 15
cliente : Rodriguez Ricardo edad: 35
cliente : Cuervo Adriana edad: 27
cliente : Prado Susana edad: 18
cliente : Gorgorio Papa edad: 76

> db.clientes.find().sort({apellido:1}).forEach(function(doc){print("cliente : " + doc.apellido + " " + doc.nombre + " edad: " + doc.edad)});
cliente : Cuervo Adriana edad: 27
cliente : Gorgorio Papa edad: 76
cliente : Lopez Juan edad: 15
cliente : Morales Maria edad: 15
cliente : Prado Susana edad: 18
cliente : Rodriguez Ricardo edad: 35
> db.clientes.find().sort({apellido:-1}).forEach(function(doc){print("cliente : " + doc.apellido + " " + doc.nombre + " edad: " + doc.edad)});
cliente : Rodriguez Ricardo edad: 35
cliente : Prado Susana edad: 18
cliente : Morales Maria edad: 15
cliente : Lopez Juan edad: 15
cliente : Gorgorio Papa edad: 76
cliente : Cuervo Adriana edad: 27
> db.clientes.find().sort({edad:1}).forEach(function(doc){print("cliente : " + doc.apellido + " " + doc.nombre + " edad: " + doc.edad)});
cliente : Lopez Juan edad: 15
cliente : Morales Maria edad: 15
cliente : Prado Susana edad: 18
cliente : Cuervo Adriana edad: 27
cliente : Rodriguez Ricardo edad: 35
cliente : Gorgorio Papa edad: 76
> db.clientes.find().sort({edad:-1}).forEach(function(doc){print("cliente : " + doc.apellido + " " + doc.nombre + " edad: " + doc.edad)});
cliente : Gorgorio Papa edad: 76
cliente : Rodriguez Ricardo edad: 35
cliente : Cuervo Adriana edad: 27
cliente : Prado Susana edad: 18
cliente : Lopez Juan edad: 15
cliente : Morales Maria edad: 15